How to use the sandbox user on MacOS app to test IAP?

  • I have signed out of Mac AppStore.
  • When I try to attempt a IAP purchase on my MacOS app I get this error message shown:

Account Not In This Store Your account is not valid for use in the U.S. store.

You must switch to the U.K. store before purchasing.

[Environment: Sandbox]

I have created fresh Sandbox users, but the app is not asking me to enter them. And based on the documentation of Apple I shouldn't enter them into the AppStore login or I get them wasted.


I have deleted the

~/Library/Containers/app-bundle-id
, rebooted the dev machine and cleared once again the build folder. But I can't get it working.


How do I get a prompt for entering the sandbox user?

Any advice would be appreciated.

Aare you validating your receipt and returning error 173 to prompt an App Store authentication?

Hi John,


This is the first time we are converting our iOS app to Mac. Sorry if some questions don't make sense.


The validation happens on our server. The moment the user attempts to purchase something it fails and that popup appears. But to answer your question, no our server doesn't return a 173 HTTP code. Why does Mac need this? Because the iOS implementation didn't need that either.


09:02:23.038 💚 DEBUG AppDelegate.handlePurchasingState():199 - User is attempting to purchase product id: com.xx.xx.mac.standard.weekly

09:05:04.304 💚 DEBUG AppDelegate.handleFailedState():241 - Purchase failed for product id: com.xx.xx.mac.standard.weekly


On a separate note, I also can't generate the receipt to send it as Base64 to my server:

09:01:46.682 💛 WARNING SubscriptionService.loadReceipt():122 - Error loading receipt data: The file “receipt” couldn’t be opened because there is no such file.


internal func loadReceipt() -> Data? {
        guard let url = Bundle.main.appStoreReceiptURL else {
            return nil
        }
       
        do {
            let data = try Data(contentsOf: url)
            return data
        } catch {
            SwiftyBeaver.warning("Error loading receipt data: \(error.localizedDescription)")
            return nil
        }
    }


I think the main issue is that I'm not able to get the prompt to enter the sandbox user.


Many Thanks,

Houman

It's not your server, but your app. When your app launches, you need to validate your receipt. This is good practice from a DRM/piracy standpoint. It is also required to test in the sandbox. When run a development-signed app on an authorized device and check your receipt, you should get a failure because you don't have a receipt. At that point, you exit the app with result 173. The operating system will notice this and prompt the user for a valid sandbox Apple ID/password. Do NOT use a real Apple ID. Once you enter valid credentials, the app store will download a sandbox receipt for your app and install the receipt into the app bundle. It would be as if the user had downloaded your app from the store. You can then make in-app purchases.


I suppose if you didn't have stand-alone receipt validation, you could just grab the receipt from the app bundle and send it to your server to validate. If you don't have a receipt, then you could just exit 173 to get one.


I've only released a couple of free iOS apps. I don't know how the validation works for iOS. I'll have to learn real soon I guess.

Hi John,


Thank you for coming back to me. Now I understand what you mean.


I have changed my code to exit with 173 when the receipt can't be generated.


internal func loadReceipt() -> Data? {
        guard let url = Bundle.main.appStoreReceiptURL else {
            return nil
        }
       
        do {
            let data = try Data(contentsOf: url)
            return data
        } catch {
            SwiftyBeaver.warning("Error loading receipt data: \(error.localizedDescription)")
            exit(173)
        }
    }


Now the app exists and the prompt appears. Thank you very much.


The issue I'm facing now is that none of my freshly created sandbox users work. I can't login with any of them, even though the password is 100% correct. I have googled and it seems several people have this issue since Catalina release. Have you experienced that before?


I know that sandbox user should never login properly into production AppStore as otherwise those accounts get burnt. So what gives that I can't login with them? I have a suspicion that the prompt is from production, as I don't see any [sandbox] flag anywhere on the promt?


Hi John,


Sorry it's me again. I have found this post here https://forums.developer.apple.com/thread/124225#399478


It is exactly what I'm experiencing. When I create a new user and run the app binary there, it works perfectly fine. It accepts my test user credentials.


But the same test user/credential are rejected when I use my main account. I think the reason could be that I previously may have used my real Apple ID account to log into the store instead of the sandbox account.


This is where you have mentioned, "Do NOT use a real Apple ID.". How can this be reverted, please? Other than deleting the whole MacBook and reinstalling it. lol


Thank you,

Houman

Hi Houman,


Did you ever end up solving this?
I'm currently having the same issue.

How to use the sandbox user on MacOS app to test IAP?
 
 
Q