StoreKit 验证错误 21002:receipt-data 属性中的数据格式错误 [英] StoreKit verification error 21002: The data in the receipt-data property was malformed

查看:54
本文介绍了StoreKit 验证错误 21002:receipt-data 属性中的数据格式错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 iPhone 4/iOS 4 设备上,沙盒 App Store 在验证过程中报告此错误:

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

21002:receipt-data 属性中的数据格式错误.

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

在 iPhone 5/iOS 6 设备上,相同的代码可以正常工作(状态 == 0,已返回收据),没有任何问题.

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

我重新启动了设备,确保 Apple ID 已注销,甚至创建了一个新的测试用户帐户.结果一样.有什么想法吗?

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

推荐答案

此错误表示您创建的用于验证的 JSON 对象格式不正确.

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

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

所以我的建议是在 iPhone 4/iOS 4 上调试相同的东西.如果你使用 Json 框架来创建 JSON 对象(用于收据验证),它只适用于 iOS 5.0 &

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.

添加我实现了几个月的代码我用SBJson写了N个解析.

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

这篇关于StoreKit 验证错误 21002:receipt-data 属性中的数据格式错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆