我一直在使用SwiftyStoreKit.verifyReceipt来确保用户仍然订阅自动可再生成员资格。我在viewWillAppear上运行了这段代码,运行得很好,但问题是它每次都会询问苹果的ID和密码,是因为应用程序仍在开发中/ in购买还没有得到苹果的验证,或者我使用的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)")
}
}发布于 2020-03-19 13:38:52
我的假设是,verifyReceipt不使用本地收据,而是从App请求它。请求收据需要用户的同意,因此将解释为什么他必须输入他的凭据。
Github上的代码指出,forceRefresh的默认值是false,但是可以将forceRefresh: false添加到verifyReceipt调用中。
另外,请您检查一下receiptString是否包含任何数据?
let receiptData = SwiftyStoreKit.localReceiptData
let receiptString = receiptData.base64EncodedString(options: [])如果是的话,请试着用本地收据做SwiftyStoreKit.verifySubscription()。你还需要输入你的证件吗?
我不知道你正在开发什么样的应用程序,但我建议不要在viewWillAppear中验证收据。当地的收据无论如何都不会改变(除了续订)。所以,在应用程序启动时,或者如果用户失去访问权限是非常重要的,我建议您使用自定义服务器。如果用户的订阅状态发生了更改,服务器将收到通知。
附带注意:目前,我建议不要使用SwiftyStoreKit__,因为他们根据来自苹果的服务器端点验证收据,而这只允许来自另一台服务器。很可能苹果会拒绝你的应用程序。
警告 不要从应用程序调用app服务器verifyReceipt端点。你不能直接在用户的设备和应用商店之间建立可信的连接,因为你不能控制连接的两端,这使得它容易受到中间人的攻击。
https://stackoverflow.com/questions/60731915
复制相似问题