iphone - StoreKit:捕获失败的恢复?

标签 iphone in-app-purchase storekit

我正在使用恢复按钮实现应用内购买功能。

我设置了一个全新的测试用户,但没有支付任何费用。

当我点击恢复按钮并使用新的测试用户登录时,我无法捕获任何委托(delegate)方法来告诉我恢复事务已失败(因为没有任何内容可以恢复)。

唯一被调用的方法是-(void) paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue*)queue,但在恢复成功的情况下也会调用此方法。

我现在能做什么?我怎样才能捕获这样的案例?

<小时/>

补充:我有一个进度指示器,上面写着“正在联系 App Store”,并且我需要一个调用,以便在失败的情况下也可以隐藏它。

最佳答案

诺亚:这是给您的代码片段:

-(void)restore {

    [self.delegate showLoadingScreen];
    [[SKPaymentQueue defaultQueue] restoreCompletedTransactions];


}

以及以下方法:

-(void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue {

    if (!queue.transactions || [queue.transactions count] == 0) {

        [self showAlertScreenWithTitle:@"Error Restoring Subscription" message:@"No subscription was found to restore."];

    } else {

        BOOL didRestore = NO;

        for (SKPaymentTransaction *t in queue.transactions) {

            if (t.transactionState == SKPaymentTransactionStateRestored || t.transactionState == SKPaymentTransactionStatePurchased) {

                NSTimeInterval now = [[NSDate date] timeIntervalSince1970] - _timeOffset;
                NSTimeInterval expire = [t.transactionDate timeIntervalSince1970] + kExplorerSubscriptionSecondLength;
                NSTimeInterval purchase = [t.transactionDate timeIntervalSince1970];

                if (purchase <= now && now <= expire) {

                    didRestore = YES;
                }

            }


        }

        if (!didRestore)
            [self showAlertScreenWithTitle:@"Error Restoring Subscription" message:@"No subscription was found to restore."];

    }    

    [self.delegate dismissLoadingScreen];

}

请告诉我这是否对您有帮助......

关于iphone - StoreKit:捕获失败的恢复?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7754900/

相关文章:

ios - 在 iOS 中调试生产应用程序?

ios - 首次应用内购买

objective-c - 自动更新 IAP : latest_receipt field

iphone - 恢复应用内购买时出现 StoreKit 错误

ios - 检查应用内支付项目是否已购买

swift - 如何将 openssl 添加到 swift 项目

iPhone 在导航 Controller 动画期间崩溃,我有什么选择?

iphone - AFNetwork 和 GoogleAPI 返回 NULL

iphone - iOS线图?

iphone - iOS - 对象被释放?