ios - StoreKit验证错误 21002 : The data in the receipt-data property was malformed

标签 ios testing app-store storekit

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

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

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

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

最佳答案

此错误表示您为验证而创建的 JSON 对象格式不正确。

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

所以我的建议是在 iPhone 4/iOS 4 上进行相同的调试。如果您使用 Json 框架创建 JSON 对象(用于收据验证),它将仅适用于 iOS 5.0 及更高版本。

添加我已经实现了几个月的代码我使用 SBJson 编写了 N 解析。

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

关于ios - StoreKit验证错误 21002 : The data in the receipt-data property was malformed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13717148/

相关文章:

ios - Swift TableView 传递选定的 Cell

python - 跟踪和测试 GUI 应用程序中的功能 (Python + Gtk3)

testing - 在 TFS 构建部署测试中找不到脚本

ios - 将应用程序提交到苹果商店时出现问题 - "This bundle is invalid"

uitableview - iPhone iOS 4 核心数据 - 程序收到信号 : “EXC_BAD_ACCESS”

ios - 当 UILabel 动态调整大小时,移动 UIView 中的 UIButton。 iOS系统

ios - 如何使标签宽度自动调整

unit-testing - 运行两个 JUnit 测试套件的分离

最近上传到 App Store 的 iPhone 应用程序在启动时崩溃

ios设置AppleLanguages并提交到应用商店