IAPHelper icon indicating copy to clipboard operation
IAPHelper copied to clipboard

App Crash if Apple's Receipt Servers return nil

Open Apps4LifeLLC opened this issue 6 years ago • 0 comments

When validating receipt, Apple's response can be nil, which causes the app to crash when it tries to convert nil to JSON via NSDictionary* rec = [IAPShare toJSON:response];

I propose a modification simply in the read-me doc's example code, to now be as follows:

[[IAPShare sharedHelper].iap checkReceipt:[NSData dataWithContentsOfURL:[[NSBundle mainBundle] appStoreReceiptURL]] AndSharedSecret:@"your sharesecret" onCompletion:^(NSString *response, NSError *error) {

    if (response)
    {

        //Convert JSON String to NSDictionary
        NSDictionary* rec = [IAPShare toJSON:response];

        if([rec[@"status"] integerValue]==0)
        {
    
          [[IAPShare sharedHelper].iap provideContentWithTransaction:trans];
            NSLog(@"SUCCESS %@",response);
            NSLog(@"Purchases %@",[IAPShare sharedHelper].iap.purchasedProducts);
        }
        else {
            NSLog(@"Fail");
        }

    }
    else {
        NSLog(@"Fail (Apple server malfunction or connection interruption)");
    }

}];

Apps4LifeLLC avatar Mar 24 '18 22:03 Apps4LifeLLC