我想知道,有没有办法注册应用内购买完成时的通知?购买或恢复失败或成功时的 IE?我想处理这四种情况,以便在发生应用内购买的视图控制器中向用户显示警报。有谁知道如何做到这一点?
问问题
57 次
1 回答
1
(void)paymentQueue:updatedTransactions: 交易状态更新时调用。您可以在完成交易时显示警报窗口。
- (void) purchaseItem:(SKProduct *) item
{
NSLog(@"Purchasing item %@", item.localizedTitle);
SKPayment *payment = [SKPayment paymentWithProduct:item];
[[SKPaymentQueue defaultQueue] addPayment:payment];
}
- (void) paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
for (SKPaymentTransaction *transaction in transactions)
{
switch (transaction.transactionState)
{
case SKPaymentTransactionStatePurchased:
[self completeTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
[self failedTransaction:transaction];
break;
case SKPaymentTransactionStateRestored:
[self restoreTransaction:transaction];
break;
default:
break;
}
}
}
- (void) completeTransaction:(SKPaymentTransaction *) transaction
{
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Transaction"
message:@"Your purchase is complete"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[message show];
// or
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(finishTransactionSuccessfully:) name:PURCHASE_NOTE object:nil];
}
于 2013-07-07T18:19:35.253 回答