IAPHelper restoreTransaction -> provideContent -> crash [__NSSetM addObject:]: object cannot be nil
PasqualePuzio opened this issue · 8 comments
Hi,
a few iOS 9 users of my app are experiencing a crash when they try to purchase one or more items. Apple and I extensively tested IAPs and we never encountered such an issue.
From what I can see in the stacktrace, looks like the restoreTransaction function is internally trying to register a 'nil' product identifier. The stacktrace is attached below.
Did anyone encounter this problem before ?
Thanks
I found this discussion which may help http://stackoverflow.com/questions/19203921/in-app-purchase-iap-process-appears-to-be-crashing-the-app-on-launch-for-one-o
Same thing suggested here http://stackoverflow.com/questions/19817130/following-in-app-purchase-app-crashing-on-startup-productidentifier-nil
With respect to IAPHelper, looks like a simple check in restoreTransaction (to avoid that a nil identifier is passed to provideContent) would easily fix the issue.
Right. We've fixed with something like this:
if (transaction.originalTransaction.payment.productIdentifier.length) {
[self provideContent: transaction.originalTransaction.payment.productIdentifier];
}
Not sure it's the best fix though...
Thanks for sharing.
I would rather do something like this:
NSString *productIdentifier;
if (transaction.originalTransaction)
productIdentifier = transaction.originalTransaction.payment.productIdentifier;
else
productIdentifier = transaction.payment.productIdentifier;
if (productIdentifier)
[self provideContent:productIdentifier];
Could the maintainer fix it ?
Sorry for reply late. I will check it this weekend and will fix it. Thank , @nanomb and @PasqualePuzio
Is this issue still in progress?
yes. Please use with
[[IAPShare sharedHelper].iap provideContentWithTransaction:trans];
instead of provideContent
Hi,
thanks for the fix. However, I don't think you actually fixed it.
Here's why:
you use the code below and then you don't check if the productIdentifier is nil or not (which is the cause of the crash). This way, when calling [_purchasedProducts addObject:productIdentifier] you'll always get the same crash.
if (transaction.originalTransaction) {
productIdentifier = transaction.originalTransaction.payment.productIdentifier;
} else {
productIdentifier = transaction.payment.productIdentifier;
}