我试图购买一些自动续订订阅使用沙盒测试用户与真实的设备和一切工作正常,当时我可以看到这个SKPaymentTransactionObserver方法也成功地工作:
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
for transaction:AnyObject in transactions {
if let trans = transaction as? SKPaymentTransaction {
switch trans.transactionState {
case .purchased:
print("Success")
SKPaymentQueue.default().finishTransaction(transaction as! SKPaymentTransaction)
break
case .failed:
print("Fail")
SKPaymentQueue.default().finishTransaction(transaction as! SKPaymentTransaction)
break
case .restored:
print("restored")
SKPaymentQueue.default().finishTransaction(transaction as! SKPaymentTransaction)
break
default:
print("Called .purchasing .deferred state")
break
}
}
}
}
我还添加了其他两个可选的SKPaymentTransactionObserver方法两个使用它们时,用户要恢复购买,这里是这些方法:
func paymentQueueRestoreCompletedTransactionsFinished(_ queue: SKPaymentQueue) {
print("Restore completed")
let transactionCount = queue.transactions.count
if transactionCount == 0{
print("No previous transactions found")
}
}
func paymentQueue(_ queue: SKPaymentQueue, restoreCompletedTransactionsFailedWithError error: Error) {
print(error)
}
下面是我还原购买调用方法:
func restorePurchasedProducts(){
SKPaymentQueue.default().add(self)
SKPaymentQueue.default().restoreCompletedTransactions()
}
但当我要恢复购买它从来没有调用func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {}
或func paymentQueueRestoreCompletedTransactionsFinished(_ queue: SKPaymentQueue) {}
,但总是打印此错误:
Error Domain=NSURLErrorDomain Code=-1001 "Cannot connect to iTunes Store" UserInfo={NSErrorFailingURLStringKey=https://sandbox.itunes.apple.com/WebObjects/MZFinance.woa/wa/inAppRegrantPurchaseHistory, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <D0FBF51A-C6B2-4CBF-99F1-110EBA5E9589>.<31>, NSErrorFailingURLKey=https://sandbox.itunes.apple.com/WebObjects/MZFinance.woa/wa/inAppRegrantPurchaseHistory, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalDataTask <D0FBF51A-C6B2-4CBF-99F1-110EBA5E9589>.<31>"
), NSLocalizedDescription=Cannot connect to iTunes Store, _kCFStreamErrorDomainKey=4, NSUnderlyingError=0x2835f73f0 {Error Domain=kCFErrorDomainCFNetwork Code=-1001 "(null)" UserInfo={_kCFStreamErrorCodeKey=-2102, _kCFStreamErrorDomainKey=4}}, _kCFStreamErrorCodeKey=-2102}
有什么方法可以解决这个错误吗?
1条答案
按热度按时间bihw5rsg1#
通过创建新的沙盒测试用户和使用它,我可以能够弄清楚。