美文网首页
[iOS]苹果内购的踩坑

[iOS]苹果内购的踩坑

作者: choici | 来源:发表于2020-03-06 18:22 被阅读0次
    1,TransactionState
    SKPaymentTransactionStatePurchased(完成)
    SKPaymentTransactionStateRestored(已付费)
    SKPaymentTransactionStateFailed(失败)
    SKPaymentTransactionStatePurchasing(添加商品到列表)
    在状态显示为完成、已付费、失败的情况时,需要调用系统API
    [[SKPaymentQueue defaultQueue] finishTransaction:tran]
    来终结订单状态。
    
    2. 卡单,提示已购买将免费恢复

    Appdelegate中didFinishLaunchingWithOptions添加监听[[SKPaymentQueue defaultQueue] addTransactionObserver:self];实现监听方法

    - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray<SKPaymentTransaction *> *)transactions{
        for (SKPaymentTransaction *transaction in transactions) {
            switch (transaction.transactionState) {
                case SKPaymentTransactionStatePurchased: {
                    //交易完成
                    if ([SKPaymentQueue defaultQueue]) {
                        [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
                    }
                }
                    break;
                case SKPaymentTransactionStateFailed: {
                    //交易失败
                    if ([SKPaymentQueue defaultQueue]) {
                        [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
                    }
                }
                    break;
                case SKPaymentTransactionStateRestored: {
                    //付费
                    if ([SKPaymentQueue defaultQueue]) {
                        [[SKPaymentQueue defaultQueue] finishTransaction: transaction];
                    }
                }
                    break;
                case SKPaymentTransactionStatePurchasing:
                    //商品添加进列表
                    break;
                default:
                    break;
            }
        }
    }
    

    相关文章

      网友评论

          本文标题:[iOS]苹果内购的踩坑

          本文链接:https://www.haomeiwen.com/subject/qrbgyctx.html