I am trying to read the [appStoreReceiptURL](https://developer.apple.com/documentation/foundation/bundle/1407276-appstorereceipturl#) to read the receipt in hopes to find the initial date of purchase or initial version the user has. The plan to use this is to migrate from a paid upfront version to a free + IAP as many might have done over the years.
I know I am under a sandbox environment, while I develop this, so the path is file:///.../StoreKit/sandboxReceipt. Currently, I don't require neither local or remote validation of the receipt for the time being so I only need to read the file.
Checking if it exists using the FileManager it says that it doesn't so I start a SKReceiptRefreshRequest to retrieve a copy of the receipt from Apple's servers. I know that receipt won't have the exact data I am looking for but as far as I know it will give me an initial install version field for this environment that's 1.0 so it'd work for testing purposes. After setting the SKRequestDelegate and starting the request when the receipt is not found neither the requestDidFinish nor didFailWithError delegate methods are called. Currently I am not able to retrieve any copy of even a "sample" receipt for the sandbox environment. This sample code I am using it's pretty simple so far and is as follows,
This is being called from the AppDelegate to first of all request a fresh receipt or load one if it's not present.
Currently I am testing this using an iPad with my Apple ID logged in but under Settings.app --> App Store --> Sandbox Account I've logged in with a sandbox account created inside the development team which this app is published under that account.
Running iOS 14b3 and Xcode 12b3.
I know I am under a sandbox environment, while I develop this, so the path is file:///.../StoreKit/sandboxReceipt. Currently, I don't require neither local or remote validation of the receipt for the time being so I only need to read the file.
Checking if it exists using the FileManager it says that it doesn't so I start a SKReceiptRefreshRequest to retrieve a copy of the receipt from Apple's servers. I know that receipt won't have the exact data I am looking for but as far as I know it will give me an initial install version field for this environment that's 1.0 so it'd work for testing purposes. After setting the SKRequestDelegate and starting the request when the receipt is not found neither the requestDidFinish nor didFailWithError delegate methods are called. Currently I am not able to retrieve any copy of even a "sample" receipt for the sandbox environment. This sample code I am using it's pretty simple so far and is as follows,
Code Block import StoreKit @objc class ReceiptFetcher : NSObject, SKRequestDelegate { let receiptRefreshRequest = SKReceiptRefreshRequest() override init() { super.init() receiptRefreshRequest.delegate = self } @objc func fetchReceipt() { guard let receiptUrl = Bundle.main.appStoreReceiptURL else { print("unable to retrieve receipt url") return } do { // if the receipt does not exist, start refreshing let reachable = try receiptUrl.checkResourceIsReachable() // the receipt does not exist, start refreshing if reachable == false { receiptRefreshRequest.start() } } catch { print("error: \(error.localizedDescription)") /* error: The file “sandboxReceipt” couldn’t be opened because there is no such file */ DispatchQueue.main.async { self.receiptRefreshRequest.start() } } } // MARK: SKRequestDelegate methods func requestDidFinish(_ request: SKRequest) { print("request finished successfully") } func request(_ request: SKRequest, didFailWithError error: Error) { print("request failed with error \(error.localizedDescription)") } }
This is being called from the AppDelegate to first of all request a fresh receipt or load one if it's not present.
Currently I am testing this using an iPad with my Apple ID logged in but under Settings.app --> App Store --> Sandbox Account I've logged in with a sandbox account created inside the development team which this app is published under that account.
Do I need to enable IAP in the AppStore Connect account so I am able to retrieve receipts?
Is receipt validation strictly necessary in this case? I wouldn't need to validate against some third party as the initial purchase has been through the App Store.
I would want to only read the fields of the receipt that show information on the initial purchase date/version. I remember did this some time ago with another app that was free but with an IAP. And AFAIK every app, either paid or free, has a receipt attached with this kind of information but being currently on a sandbox environment I am a bit confused.
Running iOS 14b3 and Xcode 12b3.