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;
}
}
}
网友评论