前言:关于In-App Purchase(内购)的注意事项
一点注意事项:
- 内购应该有游客身份的购买选项,不然可能被拒,前一段时间我这边一直是因为没有游客身份购买被拒。
- 在验证内购结果的时候要注意使用下列的代码,否则之前遇到过一个21002的状态码,这个状态码说是receipt-data的内容有问题,不过用了官方给的代码后是可以正常的验证的
关键代码如下:
NSData *receipt; // Sent to the server by the device // Create the JSON object that describes the request
NSError *error;
NSDictionary *requestContents = @{
@"receipt-data": [receipt base64EncodedStringWithOptions:]
};
NSData *requestData = [NSJSONSerialization dataWithJSONObject:requestContents
options:
error:&error]; if (!requestData) { /* ... Handle error ... */ } // Create a POST request with the receipt data.
NSURL *storeURL = [NSURL URLWithString:@"https://buy.itunes.apple.com/verifyReceipt"];
NSMutableURLRequest *storeRequest = [NSMutableURLRequest requestWithURL:storeURL];
[storeRequest setHTTPMethod:@"POST"];
[storeRequest setHTTPBody:requestData]; // Make a connection to the iTunes Store on a background queue.
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest:storeRequest queue:queue
completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
if (connectionError) {
/* ... Handle error ... */
} else {
NSError *error;
NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:data options: error:&error];
if (!jsonResponse) { /* ... Handle error ...*/ }
/* ... Send a response back to the device ... */
}
}];
参考网址:
In-App Purchase Programming Guide
Validating Receipts With the App Store(这个链接下有关于验证订单的代码 状态码 等信息)
iOS交流群欢迎你的加入!
群二维码:
先写到这么多
如有问题,敬请指正;
如需转载,请注明出处,谢谢!