How to get the local receipts generated from StoreKitTest in code?

When developing in sandbox environment, I get receipt url from  [[NSBundle mainBundle] appStoreReceiptURL] and post http request with it to sandbox server to validate.
But as StoreKitTest is a local test environment, this approach does not work ever more, I always receive respond with error 21002.

As mentioned in [https://developer.apple.com/documentation/xcode/setting_up_storekit_testing_in_xcode?language=objc)

Be sure your code uses the correct certificate in all environments. Add the following conditional compilation block to select the test certificate for testing, and the Apple root certificate otherwise.
#if DEBUG
let certificate = “StoreKitTestCertificate”
#else
let certificate = “AppleIncRootCertificate”
#endif

I know I should install the StoreKitTestCertificate.cer file for my test device, but how to use the code above in my project, and how to retrieve the receipt from the local. Is there any sample code available?




Answered by Engineer in 638851022
You can fetch the receipt using the same API you mentioned: [[NSBundle mainBundle] appStoreReceiptURL]. The certificate is to be used for local receipt validation as the verify receipt endpoint for server-to-server validation isn't supported. More in-depth documentation is available here.
Accepted Answer
You can fetch the receipt using the same API you mentioned: [[NSBundle mainBundle] appStoreReceiptURL]. The certificate is to be used for local receipt validation as the verify receipt endpoint for server-to-server validation isn't supported. More in-depth documentation is available here.
Thank you. I got that.
I do not think this question was answered. The question is not about where to fetch the receipt, rather it is a question about how to configure Storekit for IOS in XCode.

Reiterating for the original author - Where does the following configuration code belong?
As mentioned in [https://developer.apple.com/documentation/xcode/setting_up_storekit_testing_in_xcode?language=objc)
Code Block
#if DEBUG
let certificate = “StoreKitTestCertificate”
#else
let certificate = “AppleIncRootCertificate”
#endif

The problem here (and in various postings around the internet) is that the documentation requires this code snippet...somewhere, but does not say specifically where to add it.

^This is a problem with the documentation.

I hace the same problem, where does that code goes? the documentation isnt clear.

I am also confused with the documentation of this process. Where does the code belong. please elaborate.

#if DEBUG let certificate = “StoreKitTestCertificate” #else let certificate = “AppleIncRootCertificate” #endif

Hi, i faceing this Issue, any suggestions will be appricated. Thanks

Hi, i faceing this Issue, any suggestions will be appricated. Thanks

How to get the local receipts generated from StoreKitTest in code?
 
 
Q