Can't open App Store Receipt

I am rewriting the code I use to validate App Store receipts to use ComonCrypto instead of openssl. In my project is a folder named "_MASReceipt" with an example receipt that I got from Apple, called "receipt". When I call the NSURL method


[code]NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];[/code]


I get a URL that appears to be correct: "Contents/_MASReceipt/receipt.


But when I use the URL to open the receipt, for example:


[code]NSError *theError;

NSData *receiptData = [NSData dataWithContentsOfURL: receiptURL options: NSDataReadingMappedAlways error: &theError];[/code]


The NSData pointer is nil and the NSError contains this error:


domain: @"NSCocoaErrorDomain" Code: - 260


Code 260 is a file not found error.


Why cant the URL I get from the mail bundle be used to open the file?

Accepted Reply

XCode won't automatically include the _MASReceipt folder and the receipt file in the target. I had to add a build phase in XCode to copy the receipt into a _MASReceipt folder so it would be there for debugging the code. When I use the code in my applications for receipt validation this build phase won't be there so I will rely on the App Store to install a valid receipt.

Replies

If I remove the _MASReceipt/receipt folder from the project the appStoreReceiptURL method still returns the same URL. It looks like all it's doing is telling me where the receipt should be if one has been added by the App Store. According to the documentation it doesn't tell you if the file is really there. It looks like the method just returns a URL built from a string litteral: @"Contents/_MASReceipt/receipt".

NSString *resourcePath = [[NSBundle mainBundle] pathForResource:@"receipt" ofType: nil];


Won't locate the file either.

XCode won't automatically include the _MASReceipt folder and the receipt file in the target. I had to add a build phase in XCode to copy the receipt into a _MASReceipt folder so it would be there for debugging the code. When I use the code in my applications for receipt validation this build phase won't be there so I will rely on the App Store to install a valid receipt.