Code Block NSError *theError = nil; NSBundle *mainBundle = [NSBundle mainBundle]; NSURL *appStoreReceiptURL = [mainBundle appStoreReceiptURL]; NSData *receiptData = [NSData dataWithContentsOfURL: appStoreReceiptURL options: NSDataReadingMappedAlways error: &theError]; if (!receiptData) { NSURL *receiptURL = [mainBundle URLForResource: @"receipt" withExtension: @""]; receiptData = [NSData dataWithContentsOfURL: receiptURL options: NSDataReadingMappedAlways error: &theError]; }
Now it has stopped working. I have had to use both methods to get a URL to the _MASReceipt/ directory because XCode seems to do it differently when debugging. Now the application crashes the second time I try to get recieptData. Both methods return a URL with a path to @"Contents/_MASReceipt/reciept. The first time I use dataWithContentsOfURL the error and data ptr are nil. The second time the app crashes and I get a warning that the app is damaged and to download a new copy from the App Store. Looking at the build folder it appears that XCode isn't creating a _MASReceipt folder.
Do I have to put some special build instructions in the project to fix this? Why did this stop working?
Before when I couldn't get a valid receipt the program would exit and ask me to enter my test user id and password. Then it would attach a valid receipt and run the app.
URL *receiptURL = [mainBundle URLForResource: @"receipt" withExtension: @""];
anymore and when the receipt validation code calls exit(173), XCode relaunches the app with a dialog for me to enter my test user ID and password, and adds a valid receipt.
This MIGHT be because I added a build phase to the target:
Copy Files
Destination - Wrapper
Subpath - @"Contents/_MASReceipt/receipt"
If you get the same errors that I did, try the above. Maybe it will solve this problem.