【问题标题】:In-App Purchase fails and every time I get “Cannot connect to iTunes Store” with transaction status returns failed应用内购买失败,每次我收到“无法连接到 iTunes Store”,交易状态返回失败
【发布时间】:2021-02-02 10:56:00
【问题描述】:

我们一直在使用 RevenueCat 进行 IAP 自动续订订阅。我们已正确遵循 RevenueCat 集成指南,并且能够通过沙盒测试器成功测试某些设备的 IAP 订阅,并在某些设备上失败。这是 IAP 成功/失败的 50/50 情景。

不像沙盒测试用户因 IAP 失败,在生产构建中 IAP 也失败了很多次。

如果您检查我们为当前应用所做的代码实现,将会很有帮助。

AppDelegate.swift

Purchases.debugLogsEnabled = true
Purchases.configure(withAPIKey: PURCHASE_APIKEY, appUserID: UIDevice.current.identifierForVendor?.uuidString)

PremiumController -> 显示产品列表,用户可以从中选择特定包并订阅。

var selectPackage: Purchases.Package?   // Selected package reference - the package which is selected by user



// Listing of all offerings which will be displayed to user and user will select an offering from this list
        Purchases.shared.offerings { [weak self] offerings, error in
            if let pack = offerings?.current?.availablePackages {
                self?.packages = pack
                
                for i in pack {
                    if i.packageType == .annual {
                        self?.selectPackage = i
                        break
                    }
                }
                
                self?.tableView.reloadData()        // Products listing
            }
        }



// Function to purchase the package
        if let package = selectPackage {
            purchasePackage(package)
        }


    func purchasePackage(_ package: Purchases.Package) {
        if Purchases.canMakePayments() {
            Purchases.shared.purchasePackage(package) { [weak self] transaction, purchaserInfo, error, userCancelled in
                if let error = error {
                    alertError(error.localizedDescription)      // Error alert will be displayed
                    return
                }
                
                if let info = purchaserInfo?.entitlements.all["powermove.pro"], info.isActive, let date = purchaserInfo?.latestExpirationDate {
                    Settings.expiresDateStr = date.toUTCSubscriptionString
                    
                    DispatchQueue.main.async {
                        let alert = UIAlertController(title: "Success", message: nil, preferredStyle: .alert)
                        alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in
                            DispatchQueue.main.async {
                                self?.back()        // this is kind of callback function which will be called to update UI
                            }
                        }))
                        self?.present(alert, animated: true)
                    }
                }
            }
        }
    }

我们调试了代码,发现是什么时候

storeKitWrapper:(RCStoreKitWrapper *)storeKitWrapper     updatedTransaction:(SKPaymentTransaction *)transaction

被调用,transaction.transactionState 返回为SKPaymentTransactionStateFailed

我们收到错误 -> “无法连接到 iTunes Store”。下面是一些日志语句。

2020-10-19 18:06:40.657001+0530 Strong Consumer[37652:7035479] [Purchases] - DEBUG: GET /v1/subscribers/069A0745-1204-4079-8D7D-D14E95211998
2020-10-19 18:06:40.657370+0530 Strong Consumer[37652:7035479] [Purchases] - DEBUG: Offerings cache is stale, updating caches
2020-10-19 18:06:40.657607+0530 Strong Consumer[37652:7035479] [Purchases] - DEBUG: GET /v1/subscribers/069A0745-1204-4079-8D7D-D14E95211998/offerings
2020-10-19 18:06:40.663777+0530 Strong Consumer[37652:7035479] [Purchases] - DEBUG: PaymentQueue removedTransaction: monthly_5.99 AB64AECB-94AD-45CA-B836-65D0D6EC6D0C ((null) Error Domain=SKErrorDomain Code=0 "Cannot connect to iTunes Store" UserInfo={NSLocalizedDescription=Cannot connect to iTunes Store}) {
2020-10-19 18:06:40.664062+0530 Strong Consumer[37652:7035479] [Purchases] - INFO: Subscriber attributes synced successfully

【问题讨论】:

  • 我似乎主要问题是在 RevenueCat 仪表板上遗漏了一个包裹,我必须注册它,然后一切都像一个魅力。

标签: swift testing in-app-purchase in-app-subscription revenuecat


【解决方案1】:

从日志中,您会收到来自 Apple 的 SKErrorUnknown(代码 0)。不幸的是,您无法在生产中解决这些问题。要么是用户的 Apple 帐户有问题,要么是 Apple 的内部问题。

Apple 文档:https://developer.apple.com/documentation/storekit/skerrorcode/skerrorunknown

【讨论】:

    【解决方案2】:

    我也遇到了同样的问题。似乎带有 Development 和 Ad Hoc 证书的构建存在此问题。我将构建上传到 TestFlight。并且工作正常。

    【讨论】:

      猜你喜欢
      • 2011-11-16
      • 1970-01-01
      • 1970-01-01
      • 2015-09-15
      • 2017-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-18
      相关资源
      最近更新 更多