我正在使用SwiftyStoreKit处理我的应用程序中的订阅。但是,唯一无效的是兑换促销代码。我认为还原功能可以正常工作,但不能正常工作。看起来像这样:
@IBAction func restorePurchases(_ sender: Any) {
guard isConnectedToNetwork() else { return }
guard GlobalConstants.isSubscribed else {
showAlertNothingToRestore()
return
}
SwiftyStoreKit.restorePurchases(atomically: false) { results in
if results.restoreFailedPurchases.count > 0 {
log("Restore Failed: \(results.restoreFailedPurchases)")
} else if results.restoredPurchases.count > 0 {
for purchase in results.restoredPurchases where purchase.needsFinishTransaction {
// fetch content from your server, then:
SwiftyStoreKit.finishTransaction(purchase.transaction)
}
log("Restore Success: \(results.restoredPurchases)")
let when = DispatchTime.now() + .seconds(1)
DispatchQueue.main.asyncAfter(deadline: when) {
self.becomeMember()
}
} else {
showAlertNothingToRestore()
}
}
}
这只会导致“无法恢复”消息,并且促销代码无效。如何更改此代码以使其正常工作?