SwiftyStoreKit
SwiftyStoreKit copied to clipboard
verifyPurchase always returns "not Purchased"
Bug Report
I'm using code like the following in viewDidLoad at startup, but from a week or two week ago it always returns "notPurchased".
func verifyPurchase(productId:String) {
let appleValidator = AppleReceiptValidator(service: .production, sharedSecret: xxxxxx)
SwiftyStoreKit.verifyReceipt(using: appleValidator) { result in
switch result {
case .success(let receipt):
let purchaseResult = SwiftyStoreKit.verifyPurchase(productId: productId, inReceipt: receipt)
switch purchaseResult {
case .purchased:
print("purchased")
case .notPurchased:
print("notPurchased")
case .error:
print("error")
}
}
}
To Reproduce
Whenever I call verifyPurchase(productId: "zzzzzz")
in ViewDidLoad, "not Purchased" is printed.
This seems to happen for all consumable, non-consumable, auto-renewable subscription, and non-renewing subscriptions.
Expected behavior In my case, verifyPurchase with viewDidLoad always prints "notPurchased", but the purchase is successful.
When I press the buy button, it asks "You've already purchased this.Would you like to get it again for free".
Platform Information
- OS: [iOS 14.1]
- Purchase Type: [consumable, non-consumable, auto-renewable subscription, non-renewing subscription]
- Environment: [sandbox,TestFlight]
- SwiftyStoreKit version: [latest version of cocoapods]
Additional context
Even if I use the code that worked normally until a few weeks ago or the app on TestFlight as it is, verifyPurchase also fails. I suspect that this issue is caused by the influence of the iOS version and so on.
If anyone has a similar problem and finds a solution, please let me know.
Just to clarify, you state that this behavior happens for all types of IAP’s. Have you tested with all types of IAP’s? I would think consumables for example would not result in the “already purchased” message...
Also, from the readme, there are different ways to verify a purchase depending on if it’s a subscription vs a consumable product.
Do you have any additional details on this?
I also encountered the same problem, and the product type is: nonConsumable
; it can be verified during normal purchase, and every time the purchase is verified through restorePurchases
, it will return notPurchased
;
The same operation, verify that there is no problem with autoRenewable
;
The following code is not a complete code, it is my approximate operation at the time
SwiftyStoreKit.restorePurchases(atomically: true, applicationUsername: "") { results in
let successPurchases = results.restoredPurchases
successPurchases.forEach { purchase in
SwiftyStoreKit.verifyReceipt(using: AppleReceipt, forceRefresh: forceRefresh) { verifyReceiptResult in
switch verifyReceiptResult {
case .success(let receiptInfo):
switch product.type {
case .nonConsumable:
let verifyPurchase = StoreKit2.verifyPurchase(productId: product.rawValue, inReceipt: receiptInfo)
switch verifyPurchase {
case .purchased(let item):
appendLog("验证购买✅","purchased:", product.rawValue)
case .notPurchased:
appendLog("验证购买⚠️","notPurchased:", product.rawValue)
}
}
}
}
}
}
macOS 11.2 sandbox