StoreKit:Catch恢复失败? [英] StoreKit: Catch failed restore?
问题描述
我正在使用还原按钮实现应用程序内购买功能。
I'm implementing In-App purchase feature with Restore button.
我有一个全新的测试用户设置,没有任何付款。
I have a brand new test user set up, without any payments made.
当我点击恢复按钮,并使用新的测试用户登录时,我无法捕获告诉我的任何委派方法恢复交易失败(因为没有要恢复的内容)。
When I hit the restore button, and log in with the new test user, I cannot catch any delegated methods that tell me that the restoring transaction has failed (since there is nothing to restore).
唯一被调用的方法是 - (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
,但在恢复成功的情况下调用此方法。
The only method that get invoked is -(void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue*)queue
, but this method gets called in the case when restoring was successful too.
什么可以我现在做的?我怎么能抓住这样的情况呢?
What can I do now? How can I catch such a case?
另外:我有一个进度指示器,上面写着联系App Store,以及我需要一个调用,我也可以在失败的情况下隐藏它。
Addition: I have a progress indicator that says "Contacting App Store", and I need an invocation where I can hide it in failed cases too.
推荐答案
Noah:这是给你的代码片段:
Noah: here's a code snippet for you:
-(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];
}
如果有帮助,请告诉我....
Let me know if that helps you....
这篇关于StoreKit:Catch恢复失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!