StoreKit verification error 21002: The data in the receipt-data property was malformed

前端 未结 2 1130
一向
一向 2021-01-20 05:34

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.

相关标签:
2条回答
  • 2021-01-20 05:57

    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];`
    
    0 讨论(0)
  • 2021-01-20 06:05

    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.

    0 讨论(0)
提交回复
热议问题