Vikas Dadheech
Vikas Dadheech

Reputation: 1720

App crashes after purchasing auto renewable purchase with trial

I have been trying to implement auto renewable subscription (ARS) with trial period. I already had an app with ARS implemented and it was working fine. Now I wanted to add trial period as well in these subscriptions. So for testing purpose I created two new products with trial period of 1 month set in them.

Now in sandbox environment, when I try to purchase these two new products from a sandbox Id from which I already had taken the subscription, the process goes smoothly without any issue. But when I try to purchase them with a new sandbox account, app crashes after reaching updatedTransaction observer method. In this method, I have received the receipt of the product purchase and the whole transaction details. But the app crashes after this. Restore purchase for the same product works fine.

Below is the crash log and snapshot:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSDictionaryM removeObjectForKey:]: key cannot be nil' * First throw call stack: (0x186c081c0 0x18564055c 0x186b06534 0x100f052a4 0x19362ded8 0x1022e925c 0x1022e921c 0x1022ee284 0x186bb5f2c 0x186bb3b18 0x186ae2048 0x188565198 0x18cabc628 0x18cab7360 0x10065831c 0x185ac45b8) libc++abi.dylib: terminating with uncaught exception of type NSException

snapshot

Snapshot with line of crash selected

Upvotes: 3

Views: 140

Answers (1)

timgcarlson
timgcarlson

Reputation: 3146

This might not answer the above question directly, but it's the closest similar issue I could find to the one I was having. Hopefully this will save someone time if they're encountering this (skip to the bottom for the short answer).

I was getting the same stack trace exception, but for a slightly different reason:

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSDictionaryM setObject:forKeyedSubscript:]: key cannot be nil'

Note setObject:forKeyedSubscript: and not removeObjectForKey: like in the above question. I was trying to purchase an IAP with Introductory Pricing, and even though I would successfully get the confirmed receipt from Apple, it would still crash. I was able to use the product after restarting the app.

I spent way too much time trying to find deallocated delegates, swizzling Foundation object methods and creating sandbox user after sandbox user. The problem all along was with incomplete information in iTunes Connect.

The reason for the crash was because the metadata on the product in iTunes connect was incomplete. I needed to add localization names and a note to the reviewer for the product to be "Ready for review" and not "Missing metadata".

TL;DR Make sure the product you are trying to purchase is labeled as "Ready for review" and not "Missing Metadata"

Upvotes: 1

Related Questions