我一直在使用SwiftyStoreKit.verifyReceipt
以确保用户仍然订阅自动更新会员资格。我在 运行此代码viewWillAppear
,它运行良好,但问题是它每次都要求输入 Apple ID 和密码,是因为该应用程序仍在开发中/应用程序内购买尚未得到 Apple 验证还是我错误地使用 SwiftyStoreKit.verifyReceipt。
文档:https ://github.com/bizz84/SwiftyStoreKit
我在viewWillAppear中的代码:
let appleValidator = AppleReceiptValidator(service: .production, sharedSecret: "123")
SwiftyStoreKit.verifyReceipt(using: appleValidator) { result in
switch result {
case .success(let receipt):
let productId = "123"
// Verify the purchase of a Subscription
let purchaseResult = SwiftyStoreKit.verifySubscription(
ofType: .autoRenewable, // or .nonRenewing (see below)
productId: productId,
inReceipt: receipt)
switch purchaseResult {
case .purchased(let expiryDate, let items):
print("\(productId) is valid until \(expiryDate)\n\(items)\n")
OneSignal.sendTag("isUserVIPMember", value: "true")
case .expired(let expiryDate, let items):
print("\(productId) is expired since \(expiryDate)\n\(items)\n")
OneSignal.sendTag("isUserVIPMember", value: "false")
case .notPurchased:
print("The user has never purchased \(productId)")
OneSignal.sendTag("isUserVIPMember", value: "false")
}
case .error(let error):
print("Receipt verification failed: \(error)")
}
}