应用购买中的恢复未完成

时间:2014-05-22 12:38:53

标签: ios objective-c in-app-purchase

我使用以下代码开始恢复In App Purchase:

[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
SKReceiptRefreshRequest * request = [[SKReceiptRefreshRequest alloc] init];
request.delegate = self;
[request start];
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];

应用程序商店程序启动,并调用SKTransactionObserver中的此方法:

- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue

但是从不调用此方法来完成事务:

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

问题是什么,如何解决?

1 个答案:

答案 0 :(得分:2)

我发现了问题。 将xCode从5.1更新到5.1.1是原因。苹果在应用购买方式方面会有一些变化。它迫使开发人员在最新版本的xCode中进行这些更改。

顺便说一下我修改了这样的方法:

恢复请求:

NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
NSData *receipt = [NSData dataWithContentsOfURL:receiptURL];
if (!receipt) {
    SKReceiptRefreshRequest * request = [[SKReceiptRefreshRequest alloc] init];
    request.delegate = self;
    [request start];
}
[self registerAsPurchaseObserver];
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];

并回复:

-(void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error
{
    [Delegate transactionDidFail];
}

- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
{
    NSURL *receiptURL = [[NSBundle mainBundle] appStoreReceiptURL];
    NSData *receipt = [NSData dataWithContentsOfURL:receiptURL];
    if (receipt) {
        [Delegate transactionDidRestorePurchaseSuccessfullyWithReciept:receipt];
    }
    else{
        [Delegate transactionDidFail];
    }
}