saturngod / IAPHelper

No more maintenance for this repo. Please use the https://github.com/bizz84/SwiftyStoreKit
MIT License
1.55k stars 280 forks source link

IAPHelper restoreTransaction -> provideContent -> crash [__NSSetM addObject:]: object cannot be nil #20

Closed PasqualePuzio closed 7 years ago

PasqualePuzio commented 8 years ago

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

fabric

PasqualePuzio commented 8 years ago

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

PasqualePuzio commented 8 years ago

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.

nanomb commented 8 years ago

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...

PasqualePuzio commented 8 years ago

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 ?

saturngod commented 8 years ago

Sorry for reply late. I will check it this weekend and will fix it. Thank , @nanomb and @PasqualePuzio

alibasta commented 8 years ago

Is this issue still in progress?

saturngod commented 8 years ago

yes. Please use with

[[IAPShare sharedHelper].iap provideContentWithTransaction:trans];

instead of provideContent

PasqualePuzio commented 8 years ago

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;
}