当交易不存在时,无法恢复交易 应用内购买和目标 c



我有一个应用程序正在开发中。整个购买过程都在进行,当使用Apple ID进行活动购买时,恢复也在进行。但是,当用户使用登录的Apple帐户没有活动购买时单击"恢复购买"UIButton时,我想处理这种情况。

在我的AppDelegate中,我有:

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{    
for (SKPaymentTransaction *transaction in transactions)
{
switch (transaction.transactionState)
{
case SKPaymentTransactionStatePurchased:
{
// unlock the full version
[self unlockFullVersion:transaction];
[[SKPaymentQueue defaultQueue]finishTransaction:transaction];
[self saveReceipts];
break;
}
case SKPaymentTransactionStatePurchasing:
{
// currently purchasing
break;
}
case SKPaymentTransactionStateRestored:
{
[self restoreTransaction:transaction]; 
[[SKPaymentQueue defaultQueue]finishTransaction:transaction];
break;
}
case SKPaymentTransactionStateFailed:
{
// it didn't work
break;
}
case SKPaymentTransactionStateDeferred:
{
// deferred
break;
}
}
}
}
- (void)restoreTransaction:(SKPaymentTransaction *)transaction
{
if (transaction)
{
if ([transaction.payment.productIdentifier isEqualToString:@"com.company.Unlimited"])
{
[[NSNotificationCenter defaultCenter] postNotificationName:@"CheckProVersion" object:self userInfo:nil];
[[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"IAPSuccessful"];

[[NSUserDefaults standardUserDefaults]synchronize];
}
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Restore Successful" message:@"Your restore was successful." delegate:nil cancelButtonTitle:@"Thanks" otherButtonTitles:nil, nil];
[alertView show];
}
else
{
NSLog(@"The transaction does not exist");
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Restore Unsuccessful" message:@"Your Apple ID doesn't have an active purchase for upgrading to Envylope Pro. " delegate:nil cancelButtonTitle:@"Thanks" otherButtonTitles:nil, nil];
[alertView show];
}
}

在这种特殊情况下,如果事务不存在,则不会调用restoreTransaction方法中的第二个UIAlertView

我设置了一个断点,但它永远不会被调用。我在SKPaymentTransactionStateFailed案例中设置了一个断点,我看到了这一点,当我没有活跃的购买时,它会被击中。然而,这将从AppDelegate中实际执行我想要的操作(如UIAlertView),并且我只希望它在单独的InAppPurchaseViewController中运行。

问题

从这个InAppPurchaseViewController(离它只有几个屏幕),我有一个恢复UIButton,我想要的是在点击按钮的过程中执行一个测试,看看是否存在这个Apple ID的事务。这样的事情可能吗?

更新

SKPaymentTransactionStateFailed中,我放置了:

NSString * const SKErrorDomain;
NSLog(@"The error is %@", SKErrorDomain);

我得到(null)作为错误。

尝试添加此方法,它可以处理没有购买要恢复的情况:

- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue {
if (queue.transactions.count == 0){
NSLog(@"The transaction does not exist");
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Restore Unsuccessful" message:@"Your Apple ID doesn't have an active purchase for upgrading to Envylope Pro. " delegate:nil cancelButtonTitle:@"Thanks" otherButtonTitles:nil, nil];
[alertView show];
}
}

最新更新