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.
Answered by Tlaloc in 667831022
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.

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.
Accepted Answer
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.

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?

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.

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.

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...

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.

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.

XCode not creating _MASReceipt/reciept in App Bundle?
 
 
Q