在(一)中坑已经说的很多了,但只埋了一半.现在我把我意识到的坑都埋完.
没看过(一)的出门左转,这俩要一起看..抱歉篇幅问题
↓防懵逼必看
↑防懵逼必看
回去看了看貌似(一)已经可以解决所有问题了...额
1.还有订单没结束的坑
所以要把开始监听写在程序入口,在程序挂起时移除监听.
如果有未完成的订单他就会直接走
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray<SKPaymentTransaction *> *)transactions
一般情况下都是购买成功后没有结束订单的坑,所以他会走验证方法
if (self.cash != nil)这句话在这就起作用了,所以他会走[self checkUnTestReceipt];//从本地取凭证验证去 }
2.为什么要存到数组??
因为你可能出现不止一个未验证的订单,擦,好惨
- (void)checkUnTestReceipt
{
NSArray *payAry =从本地去取存凭证的数组,我就不告诉你怎么取,咬我
if (!payAry || payAry.count == 0) {
return;
}
for (NSDictionary *dic in payAry) {
[self untestReceiptByTime:dic];//把本地(漏单)的dic(验证信息)都去验证了
}
}
untestReceiptByTime:这方法只是多了个失败后的回传,和验证方法有一点不同
- (void)untestReceiptByTime:(NSDictionary *)dic//第一次访问服务器失败了又一次请求,多了个定时的请求
{
WEAKSELF;
[[YLBNetWorkManager sharedInstance]postJsonData:dic url: e successBlock:^(id responseBody) {
[weakSelf removeDicFromPayAry:dic];//移除,不懂得看一
} failureBlock:^(NSString *error) {
DLog(@"%@和自己服务器失败22",error);
[self untestReceiptByTime:dic];//最好一段时间后再验证,用GCD
}
程序入口监听开始
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
DLog(@"我一进来就看看本地漏单");
[[IAPManager sharedInstance]checkUnTestReceipt];//一进程序看看有没有漏单
双管齐下,你慢慢漏吧
当然还得在程序入口新建本地数组(只建一次),用NSUserDefaults ,删除添加都是他,这我就不写了,你全部都复制粘贴也没啥成就感..
程序出口移除监听
[[SKPaymentQueue defaultQueue] removeTransactionObserver:self];
.
3.为什么必须存到本地
为了不往本地存我是没少费劲,但是我太年轻,还是错了.
虽然只要不结束订单凭证就不会消失,但是验证时还需要其他(用户Aid,不然你怎么知道谁买的.或者下次登录换用户B了,你只用了本地的凭证和B,擦,充错人)所以必须存本地.
突然有个疑问,这个凭证是怎么和订单一一对应的?谁知道说下,我没事也研究下
4.总结
貌似无法解决用户购买后未验证但是换手机了的丢单问题,额,你找客服吧.好烦..技术有限,以后再说吧.仔细想想好像还不是很完美.以后再补充吧.也请大神们多指教吧
最后我要感谢所有帮助我的人谢谢你们五四的奉献
...
写到这里,算是把内购给写的略微明白点了.我现在也就能理解到这个水平了,以后有什么会再补充.
记得刚拿到任务一脸懵逼头大.貌似大部分内购文章里都有我浏览的身影吧.我针扎
我在想要不要加密本地的东西,还有唐巧说要禁止越狱的用户内购(他们问题太多,比如被黑客挟持)
5 更新11.1(验证)
先去苹果的正式服务器验证,返回21007的话再去测试验证.因为苹果测试用的是测试服务器
网友评论
In-App Purchase Receipt
The receipt for an in-app purchase.
ASN.1 Field Type 17
ASN.1 Field Value SET of in-app purchase receipt attributes
JSON Field Name in_app
JSON Field Value array of in-app purchase receipts
In the JSON file, the value of this key is an array containing all in-app purchase receipts. In the ASN.1 file, there are multiple fields that all have type 17, each of which contains a single in-app purchase receipt.
The in-app purchase receipt for a consumable product is added to the receipt when the purchase is made. It is kept in the receipt until your app finishes that transaction. After that point, it is removed from the receipt the next time the receipt is updated—for example, when the user makes another purchase or if your app explicitly refreshes the receipt.
The in-app purchase receipt for a non-consumable product, auto-renewable subscription, non-renewing subscription, or free subscription remains in the receipt indefinitely.
也就是说,除了消耗性商品其余所有的内购信息会永久的保存在本地,消耗性商品除非在苹果那边已经验证过了否则也会一直保存在本地,只要没有验证成功的消耗性商品都会保存在票据信息中,你每次获取这个票据时都会存有所有你之前没有验证过的商品信息。说了这么多累死了希望所有开过这篇文档的同学们看见我的评论后不要做一些无用的操作被作者误导了
第一次能购买成功,然后第二次购买能够弹出确认框,点击购买返回 SKErrorDomain Code=0 无法连接 itunes 的错误,然后再次购买,又能成功