bizz84 / SwiftyStoreKit

Lightweight In App Purchases Swift framework for iOS 8.0+, tvOS 9.0+ and macOS 10.10+ ⛺

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

App store receipt request always fails

DanielZanchi opened this issue · comments

I am performing this:

        let appleValidator = AppleReceiptValidator(service: .production, sharedSecret: "xxxxxxxxxxxx")
        SwiftyStoreKit.verifyReceipt(using: appleValidator, forceRefresh: true) { result in
            switch result {
            case .success(let receipt):
                print("success: \(receipt)")
            case .error(let error):
                print("Verify receipt failed: \(error)")
            }
        }

Getting the sharedSecret key from the AppStore Connect portal under my app -> in app purchase -> secret key

I tried to use .production and .sandbox service but I always go into failure "case .error" with this message:
Verify receipt failed: networkError(error: Error Domain=SKErrorDomain Code=0 "An unknown error occurred" UserInfo={NSLocalizedDescription=An unknown error occurred, NSUnderlyingError=0x28182ba20 {Error Domain=ASDServerErrorDomain Code=500317 "Unhandled exception" UserInfo={NSLocalizedDescription=Unhandled exception, NSLocalizedFailureReason=An unknown error occurred}}})

Any solution?

Hello @DanielZanchi. Any solution on this?

commented

Was receiving the same error and the main issue was that I installed the app via XCode, so Store Kit didn't generate a receipt for my app. To check whether the receipt is available: if let appStoreReceiptURL = Bundle.main.appStoreReceiptURL, FileManager.default.fileExists(atPath: appStoreReceiptURL.path) { ... }

to get around this, I installed production app from the App Store and then override it with my debug version via XCode (on the phone, I'm signed in with my real apple ID, but have a sandbox user setup (in Settings -> App Store -> Sandbox user)). on first try, the receipt wasn't present (not sure why), but requesting the receipt refresh fixed this for me:

let request = SKReceiptRefreshRequest()
request.delegate = self
request.start()

on next app start, the receipt was available and I could verify it successfully. btw. when I just installed via XCode and did SKReceiptRefreshRequest, the request was failing.

hope this helps someone ;).