Requesting an In App Purchase in iOS 13 fails

In App-PurchaseIos13

In App-Purchase Problem Overview


I use SwiftyStoreKit to request In App Purchases and get only this error with iOS 13:

Error: Optional(Error Domain=ASDErrorDomain Code=507 "Error decoding object" UserInfo={NSLocalizedDescription=Error decoding object, NSLocalizedFailureReason=Attempted to decode store response})

I cannot request information about the products, nor make purchases with a sand box account. However, it works fine in iOS 12.1 on my device. It does not work with the iPhone 11 simulator or an actual device with iOS 13.

I have found a lot, that the Xcode 11 GM seed 1 beta simulator had this problem, but have not found a solution yet. I also tested it with the new released Xcode 11 GM seed 2 version, but there was no fix for me.

Does anyone have a solution on how I can request and purchase In App Purchases again with iOS 13 installed?

In App-Purchase Solutions


Solution 1 - In App-Purchase

Restarting Xcode and simulator did the trick: now my in-app purchases load properly in iOS 13 simulator.

EDIT: This happens in release Xcode 11 too. And happens once in a while, but restarting Xcode and simulators still helps.

EDIT 2: In Xcode 12 beta this bug is also present. But the solution is to create new StoreKit Configuration file (in File -> New menu)

Adding StoreKit Configuration file

Then add all your products there. Use the same product id's as in AppStore Connect.

Adding products

Then add this file to Run Scheme configuration.

Setting Scheme Run options

Solution 2 - In App-Purchase

I had the same issue, iOS13 Simulators produced the same error, iOS12 Simulators were working well. I then tried out on the iPhone with iOS13 installed, there the calls were working flawlessly too.

Hoping that it'll be fixed soon in Xcode Simulators, I guess until then we are stuck with the error.

Edit: Now it seems to work also in iOS 13 Simulator Devices.

Solution 3 - In App-Purchase

Note: I've updated the answer, read the Edit part.

To share my experience, it seems that this problem does not exist any more in Xcode 11.1 GM Seed. There's no need to restart Simulators or Xcode to make in-app purchases work anymore.

I had submitted an app for review and it was rejected because of that particular error. As it turns out, it was rejected for a stupid reason as it wasn't my app's bug, however I spent hours trying to get around it.

So, just update to Xcode 11.1 GM Seed and run again. Everything will be okay.

EDIT

The issue still exists in Xcode 11.1 and apparently I was just lucky that it didn't happen to me again. However, I had a second rejection for the exact same reason. What eventually worked and made my app get approved was this:

I had to update my IAP record on App Store by editing and saving it again.

So, I recommend you to try the same; change something temporarily in your IAPs, save and then revert your changes (and save again) so records on the App Store to be refreshed.

FYI, after the second rejection Apple invalidated my IAP and therefore showed me the way. It looks like to be a known issue to them at the end.

For details read this discussion I wrote on Reddit.

Solution 4 - In App-Purchase

For those that has this issue in iOS 14.0, you still need to create the storekit configuration file as per @silvansky answer. Rather than adding it to the target, we can actully start an SKTestSession before making any product request in order to avoid the error.

if #available(iOS 14.0, *) {
    do {
        let session = try SKTestSession(configurationFileNamed: "Your_StoreKit_Configuration_File_Name")
        session.disableDialogs = true
    } catch {
        // catch error here
    }

    // Start your product request here
    let productIdentifiers = Set(["product_identifier_1", "product_identifier_2"])
    let productsRequest = SKProductsRequest(productIdentifiers: productIdentifiers)
    productsRequest.delegate = self

    // Run the request
    productsRequest.start()
}

You can refer to Apple's documentation for SKTestSession for more info: https://developer.apple.com/documentation/storekittest/sktestsession

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTimothy C.View Question on Stackoverflow
Solution 1 - In App-PurchasesilvanskyView Answer on Stackoverflow
Solution 2 - In App-PurchaseMaverick2805View Answer on Stackoverflow
Solution 3 - In App-PurchaseGabbView Answer on Stackoverflow
Solution 4 - In App-PurchaseGamz RsView Answer on Stackoverflow