问题描述
在iPhone 4/iOS 4设备上,沙盒App Store在验证过程中报告了此错误:
On a iPhone 4/iOS 4 device, sandbox App Store is reporting this error during verification:
在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 Framework创建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:收据数据属性中的数据格式错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!