2 daffodilgirl DaffodilGirl 于 2013.03.28 10:50 提问

in-App Purchases 存储以前的数据

在应用中实现In-App Purchase,遇到两个问题

这是我的实现代码:

- (IBAction)buyProduct1:(id)sender {
    SKPayment *payment = [SKPayment paymentWithProduct:product1];
    [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
    [[SKPaymentQueue defaultQueue] addPayment:payment];
}

- (IBAction)restorePurchases:(id)sender {
    [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
    [[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {

    for (SKPaymentTransaction *transaction in transactions) {
        switch (transaction.transactionState) {
            case SKPaymentTransactionStatePurchasing:

                break;
            case SKPaymentTransactionStatePurchased:

                //Can I be 100% sure that this method is only called when the product is bought?
                [self product1Bought:transaction];

                break;
            case SKPaymentTransactionStateRestored:

                //What code should I have here to safely restore product1 if the product is bought?

                break;
            case SKPaymentTransactionStateFailed:

                break;
            default:
                break;
        }
    }
}

- (void)product1Bought:(SKPaymentTransaction *)transaction {
    NSString *string = @"Product1";
    [[NSUserDefaults standardUserDefaults] setObject:string forKey:@"Product1"];
    NSLog(@"Product1 is bought");
    [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
}

1.我想保证productBought 方法是交易成功后唯一被调用的方法。
2.如何检测product1先交易,然后再调用product1Bought 方法?

1个回答

jj89757hhb
jj89757hhb   2013.07.30 14:07

你好 in app purchase老是取不到 商品信息咋办呢

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!