Mac Can't open App Store Receipt

Senor Cuete

macrumors 6502
Original poster
Nov 9, 2011
298
12
I am sick of the now deprecated openssl dependent method I am using to validate App store receipts.

I'm working on a way to do it using CommonCrypto. In my project I have a folder named _MASReceipt and in it is a test receipt from Apple called reciept.

When I use the method:
Code:
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
The URL appears to be correct: /Contents/_MASReceipt/receipt
But when I try to open the receipt with:
Code:
NSError *theError;
NSData *receiptData = [NSData dataWithContentsOfURL: receiptURL options: NSDataReadingMappedAlways error: &theError];
*receiptData is nil and the project logs an error: Domain: @"NSCocoaErrorDomain" - Code: 260

Code 260 is a file not found error. Why can't the apparently correct URL be used as a parameter to other methods?
 

Senor Cuete

macrumors 6502
Original poster
Nov 9, 2011
298
12
Interestingly the method call
Code:
NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
creates a URL "Contents/_MASReceipt/receipt" even when the _MASReceipt/receipt is not in the project. It looks like this URL is a string literal hard coded into the appStoreReceiptURL method.
 

Senor Cuete

macrumors 6502
Original poster
Nov 9, 2011
298
12
I solved this problem by adding a build phase to the XCode Project to copy the reciept into the product in a _MASReceipt folder. This will be used for debugging only. In the code that I will use for validation in the App Store should do this.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.