I have been using SwiftyStoreKit.verifyReceipt to make sure that the user is still subscribed to the auto renewable membership. I run this code at viewWillAppear, it works well, but the problem is that it keep asking for the Apple ID and password each time, is it because the app is still under development / the in app purchase have not been verified by Apple or I am using SwiftyStoreKit.verifyReceipt incorrectly.
Documentation: https://github.com/bizz84/SwiftyStoreKit
My Code in 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)")
}
}
My assumption would be that
verifyReceiptdoesn't use the local receipt, but requests it from the App Store. Requesting the receipt require the consent of the user and therefore would explain why he has to enter his credentials.The code on Github states that the default value of
forceRefreshisfalse, but could you addforceRefresh: falseto theverifyReceiptcall.Also could you please check if
receiptStringcontains any data?And if so, please try to do
SwiftyStoreKit.verifySubscription()with the local receipt. Do you still have to enter your credentials?I have no idea what kind of app you are building, but I would recommend not to verify the receipt in
viewWillAppear. The local receipt won't change anyway (except for renewals). So do it once on app start or if it is really crucial that the user loses access, to what ever he gets with your subscription, I would recommend to use a custom server. The server will be notified if something changes in the subscription status of a user.Side note: At the moment I would advise against the usage of
SwiftyStoreKit, because they verify the receipt against the server endpoint from Apple and this is only allowed from another server. Chances are that Apple will reject your app.Source