关于In-App Purchase(内购)的注意事项

前言:关于In-App Purchase(内购)的注意事项

一点注意事项:

  • 内购应该有游客身份的购买选项,不然可能被拒,前一段时间我这边一直是因为没有游客身份购买被拒。
  • 在验证内购结果的时候要注意使用下列的代码,否则之前遇到过一个21002的状态码,这个状态码说是receipt-data的内容有问题,不过用了官方给的代码后是可以正常的验证的

关键代码如下:

 1 NSData *receipt; // Sent to the server by the device
 2  
 3 // Create the JSON object that describes the request
 4 NSError *error;
 5 NSDictionary *requestContents = @{
 6     @"receipt-data": [receipt base64EncodedStringWithOptions:0]
 7 };
 8 NSData *requestData = [NSJSONSerialization dataWithJSONObject:requestContents
 9                                                       options:0
10                                                         error:&error];
11  
12 if (!requestData) { /* ... Handle error ... */ }
13  
14 // Create a POST request with the receipt data.
15 NSURL *storeURL = [NSURL URLWithString:@"https://buy.itunes.apple.com/verifyReceipt"];
16 NSMutableURLRequest *storeRequest = [NSMutableURLRequest requestWithURL:storeURL];
17 [storeRequest setHTTPMethod:@"POST"];
18 [storeRequest setHTTPBody:requestData];
19  
20 // Make a connection to the iTunes Store on a background queue.
21 NSOperationQueue *queue = [[NSOperationQueue alloc] init];
22 [NSURLConnection sendAsynchronousRequest:storeRequest queue:queue
23         completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
24     if (connectionError) {
25         /* ... Handle error ... */
26     } else {
27         NSError *error;
28         NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
29         if (!jsonResponse) { /* ... Handle error ...*/ }
30         /* ... Send a response back to the device ... */
31     }
32 }];
View Code

 

 

参考网址:

In-App Purchase Programming Guide

Validating Receipts With the App Store(这个链接下有关于验证订单的代码 状态码 等信息)

 

iOS交流群欢迎你的加入!

群二维码:

先写到这么多

如有问题,敬请指正;

如需转载,请注明出处,谢谢!

posted on 2018-02-02 10:18  ITCoderW  阅读(2489)  评论(0编辑  收藏  举报

导航