Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS App Receipt Validation - Receipt is missing in simulator and on device while debugging

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

like image 512
Basil Bourque Avatar asked Jun 08 '16 08:06

Basil Bourque


People also ask

How do you debug a Mac simulator?

In the Safari on your Mac, on the Safari menu bar, choose the "Develop" menu. Scroll to the iOS Simulator option. Select the page for debugging.

How do you inspect iPhone simulator?

You'll need to go to Settings > Advanced and check the Show Debug Menu option. Then you'll see the option to open the web inspector for the Simulator right from that menu. With the Web Inspector open, you can debug inside the Simulator just like you could right in a desktop browser with DevTools.

How do I connect my iPhone to Xcode simulator?

Open up a project in Xcode and click on the device near the Run ▶ button at the top left of your Xcode screen. Plug your iPhone into your computer. You can select your device from the top of the list. Unlock your device and (⌘R) run the application.


1 Answers

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.

like image 179
Frank Schlegel Avatar answered Nov 02 '22 17:11

Frank Schlegel