XCode not creating _MASReceipt/reciept in App Bundle?

I have been using this code for a long time to get App Store reciepts:
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.
  • I requested code level support incident from Apple Developer Support TWICE. Each time the request disappears so apparently support requests aren't really being accepted. According to my bug report there are more than ten other similar bug reports. So Apple if this is a known problem why not fix it, or at least acknowledge it?

Add a Comment

Accepted Reply

It started to work again. The debug app isn't crashing when I call the method:
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.

Post marked as downvoted Up vote reply of Tlaloc Down vote reply of Tlaloc
Post marked as solved
  • This ugly bug has reappeared this morning. XCode is building the application with the correct path for the receipt in the application's bundle: @"Contents/_MASReceipt/receipt" but when I execute the method receiptData = [NSData dataWithContentsOfURL: receiptURL options: NSDataReadingMappedAlways error: &theError]; I get the Damaged Application Alert, so I can't run debug with the receipt validation executing.

  • Having the same problem for the last 48 hours. Try different macOS/fresh install/revoke certificate. Eventually I created empty project with existing app store bundle id with exit(173) but the receipt is not downloaded.

  • In the calling environment the code that calls getReceiptData() calls exit(173) if there is no receipt. According to the latest documentation exit(173) should tell macOS to ask for one's iTunes test user ID and password. If these are valid it should fetch a valid App Store receipt, put it in the Contents/_MASReceipt/ directory and relaunch the app.

    I tested this this morning by calling exit(173) at various places in my receipt validation code and it doesn't work. Thinking that this might be a bug like the one that will only open and display the Help Book if the app is in the Applications folder, I tried this as well. No, there is a bug in mac OS Monterey 12.0.1 that makes it impossible to use this feature to debug one's receipt validation code. This means that I can't update my app at the app store because the testers at the App Store won't be able to launch my app - they will get an alert saying that the app is damaged and to reload it from the store.

    Please file a bug report. Also I filed a request for a developer support incident but I haven't gotten any help from Apple.

Replies

Looking at other posts about this problem and my earlier post several years ago, it seems that I created a build phase that created the _MASReceipt folder in the target. This is now gone. I didn't do this so it looks like a bug in XCode. How can I recreate it? This is not likely to solve the problem because the dataWithContentsOfURL crashing the App is certainly a bug. The other thread about this is six months old and there is no solution to this problem.
It started to work again. The debug app isn't crashing when I call the method:
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.

Post marked as downvoted Up vote reply of Tlaloc Down vote reply of Tlaloc
Post marked as solved
  • This ugly bug has reappeared this morning. XCode is building the application with the correct path for the receipt in the application's bundle: @"Contents/_MASReceipt/receipt" but when I execute the method receiptData = [NSData dataWithContentsOfURL: receiptURL options: NSDataReadingMappedAlways error: &theError]; I get the Damaged Application Alert, so I can't run debug with the receipt validation executing.

  • Having the same problem for the last 48 hours. Try different macOS/fresh install/revoke certificate. Eventually I created empty project with existing app store bundle id with exit(173) but the receipt is not downloaded.

  • In the calling environment the code that calls getReceiptData() calls exit(173) if there is no receipt. According to the latest documentation exit(173) should tell macOS to ask for one's iTunes test user ID and password. If these are valid it should fetch a valid App Store receipt, put it in the Contents/_MASReceipt/ directory and relaunch the app.

    I tested this this morning by calling exit(173) at various places in my receipt validation code and it doesn't work. Thinking that this might be a bug like the one that will only open and display the Help Book if the app is in the Applications folder, I tried this as well. No, there is a bug in mac OS Monterey 12.0.1 that makes it impossible to use this feature to debug one's receipt validation code. This means that I can't update my app at the app store because the testers at the App Store won't be able to launch my app - they will get an alert saying that the app is damaged and to reload it from the store.

    Please file a bug report. Also I filed a request for a developer support incident but I haven't gotten any help from Apple.

I upgraded to macOS 12.1. This does not include a new version of App Store and it DOES NOT FIX THE EXIT 173 BUG.

Today I upgraded to XCode 13.2.1. THIS PROBLEM IS NOT FIXED. It seems likely that this is a problem with the server at the App Store.

  • This has been broken for TWO MONTHS. How can I submit an update at the App Store?

Add a Comment

The many developers that have reported this to Bug Reporter have had their reports updated with "Resolution: Potential fix identified - In macOS 12.2" "Potential" doesn't sound very reassuring. If anyone is using the beta of 12.2 it would be interesting to see if it works.

  • It's not fixed for me in macOS Monterey 12.2 Beta (21D5039d).

  • Still not fixed in macOS Monterey 12.2 Release Candidate (21D48).

Add a Comment

This is fixed in macOS 12.2. The first time I built and ran my app it exited. But when I launched it again there was a test receipt in the app bundle. It didn't ask for my test user ID and password like it used to. I was logged on to the App Store with these so it looks like it will add the receipt without asking for these credentials.

Is it possible that this bug reappeared? Building my app with macOS 12.3.1 (M1) and Xcode 13.3.1, and no receipt is retrieved after exiting with 173. Tried App Store log out / log in (sandbox and regular account) as well as reboot to no avail...

  • Yes, it reappeared.

    Please file a bug report at https://feedbackassistant.apple.com . Mention report IDs FB10003596 FB10007043 FB9831929 so Apple can correlate the issues. Post your report ID here so it can be included in future reports by others.

  • This horrible bug has occurred on and off for years so it's not surprising that it would be in a new version of XCode/App Store. All you can do is file a bug report.

  • Working again without any code change at May 18th, 8:15 pm CEST: obviously Apple has fixed the backend, but no official confirmation of the issue, no response on bug reports, no corresponding system status … Apple, please work on your developer community management.

This morning I ran a project. It was fine. Then this afternoon and I got the exit 173 bug AGAIN:

datetime appname[3785:75448] Failed to fetch the MacAppStore receipt.

Alert:

“appname” is damaged and can’t be opened. Delete “appname” and download it again from the App Store.

Seriously this has been screwed up on and off for YEARS. I can't believe that Apple hasn't gotten this critical bug fixed and doesn't acknowledge it or provide a work-around. I guess I'll have to file a bug report again for the nth time but I don't know why since it never helped in the past. AAARRRGGG!

I tried to log on to the App Store to make sure that I was logged on as my iTunes test user. After two-factor authentication I entered my iTunes test user Id and password. App Store posts an alert saying that my iTunes test user has not yet been used with the App Store (BS). The alert has two buttons: "cancel "and "review" If I hit the "review" button the page displays text saying "We've run in to a problem, try again later". A problem? No **** Apple. A problem with XCode and App Store that has been broken on and off for about FIVE YEARS.

And yes, I did file a bug Report AGAIN.

  • This is still broken this morning. There are two problems:

    The server that provides an App Store test receipt to XCode is broken, as usual.XCode needs to fetch a new receipt when you clear the build folder or build a new version but NOT when you just change a few lines of code.

    I am appalled that Apple wouldn't fix this after years of trouble for developers.

  • I can confirm that this is broken again. System Status https://developer.apple.com/system-status/ reads: "All services are operating normally."

    What is the feedback ID of your bug report? The last report I filed had no related reports showing.

Add a Comment

Feedback ID: FB10211910 this time. Also FB10023318 and FB9760796.

It's working again this morning. It isn't asking for my user ID and password. I'm going to make a copy of the receipt so if this stops working again as it has in the past I will be able to include it in my project as a build phase.