MKStoreKit icon indicating copy to clipboard operation
MKStoreKit copied to clipboard

MKStorekit crash on validating receipt.

Open aryamobomo opened this issue 9 years ago • 15 comments

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"];

aryamobomo avatar Mar 31 '15 07:03 aryamobomo

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 avatar Mar 31 '15 09:03 otranzer

It seems it is actually the same issue as #221

otranzer avatar Mar 31 '15 09:03 otranzer

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

        [self.purchaseRecord setObject:originalAppVersion forKey:kOriginalAppVersionKey];

gmeroz avatar Apr 06 '15 20:04 gmeroz

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

cujo30227 avatar Apr 07 '15 20:04 cujo30227

Please check out Whether if shared secret is correct?

xdream86 avatar Jun 15 '15 07:06 xdream86

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

jonlidgard avatar Jun 16 '15 22:06 jonlidgard

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.

groupboard avatar Jun 29 '15 15:06 groupboard

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

mistakent avatar Jul 17 '15 08:07 mistakent

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.

groupboard avatar Jul 17 '15 13:07 groupboard

Awesome!

mistakent avatar Jul 17 '15 17:07 mistakent

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

groupboard avatar Jul 20 '15 23:07 groupboard

Thanks @dwj.

cliffjoyce avatar Jul 22 '15 21:07 cliffjoyce

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

linked67 avatar Aug 19 '15 22:08 linked67

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.

groupboard avatar Aug 19 '15 23:08 groupboard

Thanks for your help dwj

linked67 avatar Aug 20 '15 08:08 linked67