ios subsciptions don't auto renew in sandbox ios subsciptions don't auto renew in sandbox swift swift

ios subsciptions don't auto renew in sandbox


For anyone dealing with this problem in 2019 or later.

I also experienced subscriptions not being automatically renewed.

In my case auto renewals stopped working after buying 6 times within 8 hours.

Details:

A one month subscription in the Sandbox lasts 5 minutes and is automatically renewed 6 times (the entire purchase expires in 30 minutes). After that you have to buy again and the same process starts over.

For automatic renewals there is however a limit of buying 6 times for every 8 hour period.

This limit is per test user per 8 hours, so you can simply use a new test users to get around this.

Under

Settings -> iTunes & App Store

there is now a new option for Sandbox Account where you can log out and log in for a new test user. This took me a long time to figure out.

The following can be used to get the receipt from apple

static func getReceipt() -> String? {    guard let url = Bundle.main.appStoreReceiptURL,        let _ = try? Data(contentsOf: url) else {            print("no receipt exists")            return nil    }    do {        let receipt = try Data(contentsOf: url)        print("receipt-data: \(receipt.base64EncodedString(options:[]))")        return receipt.base64EncodedString(options: [])    }    catch {        print("catch error")        return nil    }   }


Instead of attempting to 'Build and Run' your App each time, try to reopen the App by reopening it on the device directly. I found this way, I can refresh the subscription receipts, based upon the prior sandbox receipt.

It appears that each time you 'Build and Run' via Xcode that any pending subscription renewals are reset. Potentially rebuilding your App is the reason that the subscription auto-renew is reset.