zoukankan      html  css  js  c++  java
  • 关于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交流群欢迎你的加入!

    群二维码:

    先写到这么多

    如有问题,敬请指正;

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

    我会不定期分享 iOS 相关技术文章
  • 相关阅读:
    css3新特性总结
    H5新特性总结
    小程序本地移除有一条数据
    字符串截取(某个指定字符前面和后面的值)(指定前几位后几位)
    uni-app 创建项目
    数组转数组对象及数组对象中的某个属性值拼成一个数组
    VUE 解决单页使用keep-alive页面返回不刷新的问题
    小程序弹窗真机不动
    js 数组去重方法
    VUE 列表页中实现分页(下拉到底部触发下一页 )
  • 原文地址:https://www.cnblogs.com/ITCoderW/p/8403787.html
Copyright © 2011-2022 走看看