您已购买此 App 内购买项目。此项目将免费恢复。This In-App purchase has already been bought.It will be restored for free.

问题如下:


当内购产品类型为:消耗型项目


内购沙盒测试账号在支付成功后,再次购买相同 ID 的物品,会提示如下内容的弹窗。

您已购买此 App 内购买项目。此项目将免费恢复

您已购买此 App 内购买项目。此项目将免费恢复。This In-App purchase has already been bought.It will be restored for free._第1张图片




解决方法:要实现自己的恢复机制

在使用[[SKPaymentQueue defaultQueue] addPayment:payment];

将支付信息添加进苹果的支付队列后,苹果会自动完成后续的购买请求,在用户购买成功或者点击取消购买的选项后回调

 - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transaction;

方法返回响应的结果信息,在该方法内除了得到响应的支付信息编写自身的业务的代码外还要记得调用

[[SKPaymentQueue defaultQueue] finishTransaction:transaction];

方法通知苹果的支付队列该交易已经完成,否者就会已发起相同 ID 的商品购买就会有此项目将免费恢复的提示。


- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transaction{
    for(SKPaymentTransaction *tran in transaction){
        
        switch (tran.transactionState) {
            case SKPaymentTransactionStatePurchased: {
                NSLog(@"交易完成");
                [[SKPaymentQueue defaultQueue] finishTransaction:tran];
            }
                break;
            case SKPaymentTransactionStatePurchasing:
                NSLog(@"商品添加进列表");
                break;
            case SKPaymentTransactionStateRestored:
                NSLog(@"已经购买过商品");
                break;
            case SKPaymentTransactionStateFailed:{
                NSLog(@"交易失败");
                [[SKPaymentQueue defaultQueue] finishTransaction:tran];}
                break;
            default:
                break;
        }
        
    }
}


你可能感兴趣的:(您已购买此 App 内购买项目。此项目将免费恢复。This In-App purchase has already been bought.It will be restored for free.)