IAPHelper
IAPHelper copied to clipboard
App Crash if Apple's Receipt Servers return nil
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)");
}
}];