想知道,是否有一种方法可以在应用内购买完成时注册通知?当购买或还原失败或成功时,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];
}

关于iphone - 在应用内购买完成时可能会收到通知吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17513595/

10-14 20:47