我有一个具有inApp购买功能的应用程序。问题是即使出现错误(例如由于“无法连接到iTunes Store”而失败),系统对话框也会显示“您已经准备就绪。购买成功”。您可以在下面找到我的inApp购买帮助程序类代码。
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
}
}
}
交易失败功能
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)")
}
在应用程序进入更新交易功能之前,“一切都准备就绪”。对话框已经显示。
答案 0 :(得分:0)
似乎是苹果的最新错误。我今天开始体验它,它是在使用沙盒帐户进行购买时出现的。 但是,如果您将应用程序上载到TestFlight,则应用程序内购买仍然有效。
答案 1 :(得分:0)
Apple Sandbox出现问题,现已解决-https://developer.apple.com/system-status/