标签:
内购的关键类:
1.SKPayment(SKMutablePayment可将自己的参数一对一与苹果产生的payment对应起来)
2.TransactionObserver:交易状态更新时执行此方法,此方法会传入交易SKPaymentTransaction数组,对数组进行遍历,对不同状态进行对应的操作
(SKPaymentTransactionStatePurchasing,SKPaymentTransactionStatePurchased,SKPaymentTransactionStateFailed,SKPaymentTransactionStateRestored,SKPaymentTransactionStateDeferred)
3.SKPaymentTransaction:包括transactionReceipt,payment,transactionIdentifier等关键属性,transactionReceipt是后端验签的关键。
内购流程1:
SKPayment *payment = [SKPayment paymentWithProductIdentifier:productID];//传入productID
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];//添加observer,并执行协议,对支付状态进行更新
//observer代理方法
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
for (SKPaymentTransaction *transaction in transactions)
{
switch (transaction.transactionState)
{
case SKPaymentTransactionStatePurchased:
//对已经支付的状态进行操作
break;
case SKPaymentTransactionStateFailed:
//支付失败的操作
break;
case SKPaymentTransactionStateRestored:
//对于非消耗产品的操作
break;
default:
break;
}
}
}
如果用户已经支付,但是验签没有通过,继续支付时会产生可免费恢复的对话框,这时即使再添件payment,也都是purchasing的状态,必需将purchased状态的paymenttrananction 通过[[SKPaymentQueue defaultQueue] finishTransaction:transaction]后才能逐个执行paymentque里面purchasing状态下的订单(这是针对同一个productIdentifier的产品),不同的productIdentifier产品仍可正常支付
标签:
原文地址:http://www.cnblogs.com/hnoringin/p/5205506.html