3

On a iPhone 4/iOS 4 device, sandbox App Store is reporting this error during verification:

21002: The data in the receipt-data property was malformed.

On a iPhone 5/iOS 6 device, the same code works (status == 0, receipt returned) without any problems.

I've restarted the device, made sure the Apple ID is logged out, even made a new test user account. Same result. Any ideas?

2 Answers 2

4

This Error means the JSON Object that you have created to send for verification is not in correct format.

{
    "receipt-data" : "(receipt bytes here)"
}

So My suggestion is to Debug the same on iPhone 4/iOS 4. In case, you are Using Json Framework to create JSON object (for receipt validation) it will work only with iOS 5.0 & above.

Adding Code I had Implemented a few months I Used SBJson to write N parse.

NSString *base64TxReceiptStr=[NSData Base64Encode:transaction.transactionReceipt];

SBJsonWriter *writer = [[SBJsonWriter alloc] init];
NSDictionary *command = [NSDictionary dictionaryWithObjectsAndKeys:
                         base64TxReceiptStr, @"receipt-data",
                         nil];
NSString *jsonString = [writer stringWithObject:command];
NSData *requestBody=[jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSMutableURLRequest *txReceiptVerificationRequest=[[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://sandbox.itunes.apple.com/verifyReceipt"]];
[txReceiptVerificationRequest setHTTPBody:requestBody];
[txReceiptVerificationRequest setHTTPMethod:@"POST"];

NSURLResponse *response=nil;
NSError *error=nil;
NSData *responseData=[NSURLConnection sendSynchronousRequest:txReceiptVerificationRequest returningResponse:&response error:&error];
NSString * receivedString=[[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];


SBJsonParser *parser = [[SBJsonParser alloc] init];
NSDictionary *aobject =[parser objectWithString:receivedString];`
3
  • Thanks. I didn't realize NSJSONSerialization was iOS5+; dataWithJsonObject: method was returning nil! No exceptions, no crashes.
    – Morrowless
    Dec 5, 2012 at 6:45
  • 1
    This also happens on the new iOS6 jailbroken devices with perfectly formed JSON. The 'malformed' condition happens because the jailbroken receipts are not signed by Apple (instead the receipt has a fake signature which is the base64 hash of some timestamp). Apr 3, 2013 at 8:04
  • by the way, if you ever use ' instead of " it will fail with the same status code Dec 19, 2014 at 16:21
1

For your sandbox environment use: https://sandbox.itunes.apple.com/verifyReceipt

For actual verification use: https://buy.itunes.apple.com/verifyReceipt

You can check this at Apple's official page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.