1

I have an app which has inApp purchase feature. The problem is even if I get error, such as the fail case because of "Cannot connect to iTunes Store", the system dialog says "You are all set. Your purchase was successful". You can find my inApp purchase helper class code down.

  public func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
    for transaction in transactions {
        switch (transaction.transactionState) {
        case .purchased:
            NotificationCenter.default.post(name: .IAPHelperSetPepqueenNotification, object: nil)

            if let url = Bundle.main.appStoreReceiptURL {
                guard let receipt = try? Data(contentsOf: url) else {
                    print("error to take receipt")
                    return
                }
                let receiptData: String = receipt.base64EncodedString(options: .init(rawValue: 0))
                PepappNetwork.request(target: .postReceipt(platform: "ios", receipt: receiptData) , success: { (JSON) in
                    print(JSON)
                    let user = User(JSON: JSON["data"].dictionaryObject!)
                    UserDefaults.standard.set(user?.identifier, forKey: "userID")
                    user?.persist()

                    if user?.language != nil {
                        UserDefaults.standard.set(user!.language!, forKey: "forcedLanguage")
                        UserDefaults(suiteName: Constants.UserDefaults.containerName)!.set(user!.language!, forKey: "forcedLanguage")
                    }

                    NotificationCenter.default.post(name: Notification.Name.CurrentUserChanged, object: nil)
                    self.complete(transaction: transaction)

                }, error: { (errorString, _) in

                }) { (MoyaError) in

                }
            }
            break
        case .failed:
            NotificationCenter.default.post(name: .IAPHelperCancelNotification, object: nil)
            fail(transaction: transaction)
            break
        case .restored:
            restore(transaction: transaction)
            break
        case .deferred:
            break
        case .purchasing:
            break
        }
    }
}

Fail transaction func

private func fail(transaction: SKPaymentTransaction) {
    print("fail...")
    if let transactionError = transaction.error as NSError?,
        let localizedDescription = transaction.error?.localizedDescription,
        transactionError.code != SKError.paymentCancelled.rawValue {
        print("Transaction Error: \(localizedDescription)")

    }

Before app enter update transactions function "You're all set." dialog has already been show.

Bob Dalgleish
  • 8,167
  • 4
  • 32
  • 42
Alihan
  • 628
  • 4
  • 10
  • 1
    This seems to be a widespread issue in Sandbox right now: https://twitter.com/RevenueCat/status/1106235357413036032 – enc_life Mar 14 '19 at 16:48

2 Answers2

0

Seems like it's a recent Apple bug. I started experiencing it today and it appears when making purchase with sandbox account. However, in-app purchases still work if you upload an app to TestFlight.

Kirill Kuzyk
  • 99
  • 1
  • 7
0

There was an issue with the Apple Sandbox, It has been resolved now - https://developer.apple.com/system-status/

Deepak
  • 724
  • 4
  • 13