【发布时间】:2015-06-28 16:00:54
【问题描述】:
我有一个正在开发应用内购买的应用。整个购买过程正在运行,当使用 Apple ID 进行有效购买时,恢复也正在运行。但是,当用户点击“恢复购买”UIButton 时,如果没有使用登录的 Apple 帐户进行购买活动,我想处理这种情况。
在我的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) 作为错误。
【问题讨论】:
标签: ios objective-c iphone uibutton in-app-purchase