title: Why app does crash when trying to buy in App Store, but everything works in the sandbox (iOS)?
body: <p>Good day everyone!</p>
  
  <p>The problem is the following: when I test the application in the sandbox, everything works fine. And the application appears in App Store and crashes when you try to buy. The purchase is not consumable. </p>
  
  <p>Some facts that may lead to the right thought:</p>
  
  <ul>
  <li>Crash occurs after the lines:
  let payment = SKPayment (product: subscription.product);
  SKPaymentQueue.default().Add(payment)</li>
  <li>The application does not crash "instantly", but after ~ 1 second, which means that it crashes after some response from the server</li>
  <li>The window with the input of the password, login, confirmation of the purchase does not appear on the screen. Crash happens before that.</li>
  <li>This app has been posted to App Store as an update of the old one. It was created in a new project, in which the bundle id was changed to the bundle id of the old application.</li>
  <li>All purchases in itunesconnect approved by the moderator, they are displayed in App Store.</li>
  </ul>
  
  <pre><code>class BillingManager: NSObject {
  
      static let sessionIdSetNotification = Notification.Name("SubscriptionServiceSessionIdSetNotification")
      static let optionsLoadedNotification = Notification.Name("SubscriptionServiceOptionsLoadedNotification")
      static let restoreSuccessfulNotification = Notification.Name("SubscriptionServiceRestoreSuccessfulNotification")
      static let purchaseSuccessfulNotification = Notification.Name("SubscriptionServiceRestoreSuccessfulNotification")
  
      private override init() { }
      private static var instance: BillingManager?
  
      /** создает 1 объект или возвращает текущий (синглтон) */
      static func shared() -&gt; BillingManager {
          if instance == nil {
              instance = BillingManager()
          }
          return instance!
      }
  
      var isPro: Bool {
  
          /** Здесь проверяем дату подписки по UserDefaults */
  
          var subscriptionAccess = false
  
  
          if let purchase = UserDefaults.standard.string(forKey: "purchaseDate") {
              if let expires = UserDefaults.standard.string(forKey: "expiresDate") {
                  if let purchaseDate = dateFormatter.date(from: purchase), let expiresDate = dateFormatter.date(from: expires) {
  
                      subscriptionAccess = (purchaseDate...expiresDate).contains(Date())
  
                  }
              }
          }
  
          return (currentSubscription != nil) || subscriptionAccess || UserDefaults.standard.bool(forKey: "forever.subscription")
      }
  
      var hasReceiptData: Bool {
          return loadReceipt() != nil
      }
  
      var currentSessionId: String? {
          didSet {
              NotificationCenter.default.post(name: BillingManager.sessionIdSetNotification, object: currentSessionId)
          }
      }
  
      var currentSubscription: PaidSubscription?
  
      var options: [Subscription]? {
          didSet {
              NotificationCenter.default.post(name: BillingManager.optionsLoadedNotification, object: options)
          }
      }
  
      func loadSubscriptionOptions() {
          let productIDs = Set([InAppType.month.rawValue,
                                InAppType.halfYear.rawValue,
                                InAppType.year.rawValue,
                                InAppType.forever.rawValue,
                                InAppType.discountedForever.rawValue])
  
          let request = SKProductsRequest(productIdentifiers: productIDs)
          request.delegate = self
          request.start()
      }
  
      func purchase(subscription: Subscription) {
          let payment = SKPayment(product: subscription.product)
          SKPaymentQueue.default().add(payment)
      }
  
      func restorePurchases() {
          SKPaymentQueue.default().restoreCompletedTransactions()
      }
  
      func uploadReceipt(completion: ((_ success: Bool) -&gt; Void)? = nil) {
  
          if let receiptData = loadReceipt() {
              Service.shared.upload(receipt: receiptData) { [weak self] (result) in
                  guard let strongSelf = self else { return }
                  switch result {
                  case .success(let result):
                      strongSelf.currentSessionId = result.sessionId
                      strongSelf.currentSubscription = result.currentSubscription
                      completion?(true)
                  case .failure(let error):
                      print(" Receipt Upload Failed: \(error)")
                      completion?(false)
                  }
              }
          }
      }
  
      private func loadReceipt() -&gt; Data? {
          guard let url = Bundle.main.appStoreReceiptURL else {
              return nil
          }
  
          do {
              let data = try Data(contentsOf: url)
              return data
          } catch {
              print("Error loading receipt data: \(error.localizedDescription)")
              return nil
          }
      }
  
  }
  
  
  extension BillingManager: SKProductsRequestDelegate {
      func productsRequest(_ request: SKProductsRequest, didReceive response: SKProductsResponse) {
          options = response.products.map { Subscription(product: $0) }.sorted(by: { (left, right) -&gt; Bool in
              left.product.price &lt; right.product.price
          })
  
      }
  
      func request(_ request: SKRequest, didFailWithError error: Error) {
          if request is SKProductsRequest {
              print("Subscription Options Failed Loading: \(error.localizedDescription)")
          }
      }
  }
  </code></pre>