IAP内购问题
// 用户信息与订单号保存到支付对象
SKMutablePayment * payment = [SKMutablePayment paymentWithProduct:product];
payment对象会保存一些参数。
#pragma mark - 苹果支付事务回调(SKPaymentTransactionObserver) - (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions { for (SKPaymentTransaction *transaction in transactions) { switch (transaction.transactionState) { case SKPaymentTransactionStateFailed: //交易失败 { [[SKPaymentQueue defaultQueue] finishTransaction: transaction]; } break; case SKPaymentTransactionStatePurchased: //交易完成 { } break; case SKPaymentTransactionStatePurchasing: //商品添加进列表 { } break; case SKPaymentTransactionStateRestored: // 恢复购买 { } break; default: break; } } }
有些购买行为会在接收到SKPaymentTransactionStateFailed状态后,紧接着收到SKPaymentTransactionStatePurchased状态。
由于在接收到失败状态执行了[[SKPaymentQueue defaultQueue] finishTransaction: transaction],接收到SKPaymentTransactionStatePurchased回调时,transaction是一个新的对象,transaction.payment对象存储的值已经不存在。