9

Why would my app lack an Receipt while in development?

I am running my iOS (7, 8, 9) app from Xcode 7.3.1. The app’s Receipt seems to be missing. This app is currently shipping in the App Store, so I have my developer credentials, and a “sandbox” user login.

Simulator

When running the following code:

NSURL* url = [[NSBundle mainBundle] appStoreReceiptURL];
NSLog(@"url: %@", url);

The result in the Simulator 9.3 for iPhone 6s Plus:

file:///Users/Bourque/Library/Developer/CoreSimulator/Devices/7F32850A-CC1A-45A3-8ED6-95C75CD9DD44/data/Containers/Data/Application/46BDF021-D2A3-418E-91E1-61A15215942B/StoreKit/receipt

Yet when I navigate to the folder named with the 2nd UUID, I find no StoreKit folder.

Real device

To test on a real iOS iPod touch, I expand that code to…

…See where the Receipt should be found.

NSURL* url = [[NSBundle mainBundle] appStoreReceiptURL];
NSLog(@"url: %@", url);

…Try to load such a file.

NSString* urlContents = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
NSLog(@"urlContents: %@", urlContents);

…Verify if the file exists.

NSError *err;
if ( [url checkResourceIsReachableAndReturnError:&err] == NO ) {
    NSLog(@"BAD No receipt found for url: %@" , url );
} else {
    NSLog(@"GOOD Receipt found for url: %@" , url );
}

Results when run.

url: file:///private/var/mobile/Containers/Data/Application/21430192-6E3A-4929-B847-23FD525D804E/StoreKit/sandboxReceipt

urlContents: (null)

BAD No receipt found for url: file:///private/var/mobile/Containers/Data/Application/21430192-6E3A-4929-B847-23FD525D804E/StoreKit/sandboxReceipt

file:///private/var/mobile/Containers/Data/Application/B1497F0D-95A7-4AD8-A9D5-7AF95663A04F/StoreKit/sandboxReceipt

Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154

1 Answers1

17

Since you installed the app via Xcode and not from the Store it contains no receipt. However, you can start a SKReceiptRefreshRequest in order to get a sandbox receipt you can use for testing.

Also be aware that you need to log out of the App Store and use a test user account (created in iTunes Connect) when prompted to log in after you started the request to make it work.

Frank Rupprecht
  • 9,191
  • 31
  • 56
  • 2
    Tremendously useful answer. Thanks Frank. Another top tip here: Since iOS 12, in Settings > iTunes & App Store > scroll to the bottom and you should see a section called 'Sandbox Account' and a field which will allow you to sign in with a test user account (created in App Store Connect). I still had to do the 'sign out dance' with a real Apple ID to get the initial receipt refresh, loading and validation to work. But having this setup allows you to perform sandbox transactions in your development apps built in Xcode whilst signed in to that device with a real Apple ID – Neil Smith May 02 '19 at 09:51
  • This is super useful. Thanks for sharing! – Frank Rupprecht May 02 '19 at 10:28
  • 1
    Quick follow up on this. I've noticed that even though it's possible to sign in via Settings > iTunes & App Store > Sandbox Account, avoid doing this. Instead, if this is the first time installing an Xcode development build on a device: 1) Ensure that you are signed out of your real 'iTunes & App Store account. 2) Build and run from Xcode. 3) If your app runs receipt validation code at launch, you should then be prompted for sign in with both email and password - use the sandbox account. 4) Receipt is now present and you will be able to sign back in to your real iTunes & App Store account. – Neil Smith May 07 '19 at 18:43