MugunthKumar / MKStoreKit

The "Goto" In App Purchases Framework for iOS 8+
2.09k stars 430 forks source link

MKStorekit crash on validating receipt. #227

Open aryamobomo opened 9 years ago

aryamobomo commented 9 years ago

NSInvalidArgumentExceptionMKStoreKit -[NSNull objectForKeyedSubscript:]: unrecognized selector sent to instance 0x19932eba0

MKStoreKit crashes on validating receipts in the method startValidatingAppStoreReceiptWithCompletionHandler..

Crash is happening in the line NSArray *inAppReceipts = jsonResponse[@"receipt"][@"in_app"];

otranzer commented 9 years ago

Got the same crash in my app. It seems to be in the line 330 of MKSoreKit.m:

[MKStoreKit startValidatingAppStoreReceiptWithCompletionHandler:]_block_invoke (MKStoreKit.m:330)

otranzer commented 9 years ago

It seems it is actually the same issue as #221

gmeroz commented 9 years ago

I get nil in this line and it crashes on the next line:

        [self.purchaseRecord setObject:originalAppVersion forKey:kOriginalAppVersionKey];
cujo30227 commented 9 years ago

I also experience this crash in a released version, but it seems to affect 100% only Jailbroken devices....

xdream86 commented 9 years ago

Please check out Whether if shared secret is correct?

jonlidgard commented 9 years ago

I'm getting crashes too, modded code to make sure originalAppVersion in non nil, but haven't tested yet.

groupboard commented 9 years ago

No, unfortunately just checking originalAppVersion for nil doesn't stop the crashes, as I'm still getting them. The crash happens before originalAppVersion is used. The problem is that jsonResponse[@"receipt"] is returning an NSNull object, so I think you just need to check for NSNull before those lines:

if (jsonResponse[@"receipt"] != [NSNull null]) { NSString *originalAppVersion = jsonResponse[@"receipt"][@"original_application_version"]; if (originalAppVersion != nil) { [self.purchaseRecord setObject:originalAppVersion forKey:kOriginalAppVersionKey]; [self savePurchaseRecord]; } }

I haven't tested this yet though.

mistakent commented 9 years ago

Anyone have any success yet? Strange to see so many crashes here daily

groupboard commented 9 years ago

Yes, my fix seems to be working so far. It's been on the app store for a few weeks now, with no new crashes.

mistakent commented 9 years ago

Awesome!

groupboard commented 9 years ago

It looks like jsonResponse[@"receipt"][@"in_app"] is also crashing when the receipt is NSNull, so that needs to be checked too. Also I'm calling completionHandler(nil, nil) in cases where I'm finding these null cases.

I'll create a pull request in a month or two once I'm sure I've fixed all the crashes. In the meantime, here is my current version of MKStoreKit.m:

http://pastebin.com/WMTQC1Sh

cliffjoyce commented 9 years ago

Thanks @dwj.

linked67 commented 9 years ago

Is MugunthKumar still active to fix this on the main code ? It's a frequent bug that is open for months now.

groupboard commented 9 years ago

My fix seems to be working well -- no crashes in the last month. I've just created a pull request. I also tidied up the code a little and fixed a few bugs with #includes which were causing it to fail to compile.

linked67 commented 9 years ago

Thanks for your help dwj