0
我想知道,有没有办法在应用程序购买完成时注册通知? IE购买还是恢复失败或成功?我想处理这四种情况,以便我可以在应用程序购买发生的视图控制器中向用户显示警报。有谁知道如何做到这一点?在应用程序购买完成后可能会收到通知吗?
我想知道,有没有办法在应用程序购买完成时注册通知? IE购买还是恢复失败或成功?我想处理这四种情况,以便我可以在应用程序购买发生的视图控制器中向用户显示警报。有谁知道如何做到这一点?在应用程序购买完成后可能会收到通知吗?
(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];
}
您是否在谈论实施“SKPaymentTransactionObserver”?它应该遵循Objective-C中的“观察者模式”,以便在交易完成时得到通知(http://www.a-coding.com/2010/10/observer-pattern-in-objective-c.html) –