我现有应用程序的更新已于今天在应用商店发布,并通过应用内购买来移除广告。我不得不放置一个恢复按钮,因为它是非消耗品的应用内购买。我注意到我可以在不购买的情况下恢复应用内购买。
该应用程序大约4小时前开始销售。对于新应用来说这是正常的吗?应用商店是否需要一些时间来连接应用内购买(可能是一个愚蠢的问题)?或者我在代码中做错了什么?
如果你知道发生了什么,请回复。
编辑: 这是我使用的代码
- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{
for (SKPaymentTransaction *transaction in transactions)
{
switch (transaction.transactionState)
{
case SKPaymentTransactionStatePurchased:
[self completeTransaction:transaction];
break;
case SKPaymentTransactionStateRestored:
break;
case SKPaymentTransactionStateFailed:
[self failedTransaction:transaction];
break;
default:
break;
}
}
}
- (void) restoreTransaction: (SKPaymentTransaction *)transaction
{
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
[[SKPaymentQueue defaultQueue]addTransactionObserver:self];
}
-(void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
{
if (SKPaymentTransactionStatePurchased)
{
//save purchase
NSUserDefaults *savePurchase = [NSUserDefaults standardUserDefaults];
[savePurchase setBool:TRUE forKey:k_Save];
[savePurchase synchronize];
_adBanner.hidden = YES;
// alert after successful restore.
UIAlertView *restoreTransactionAlert = [[UIAlertView alloc] initWithTitle:@"Congratulations!"
message:@"Your purchase is restored."
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[restoreTransactionAlert show];
}
else
{
// alert after unsuccessful restore.
UIAlertView *restoreTransactionAlert = [[UIAlertView alloc] initWithTitle:@"Restore failed"
message:@"Restore failed. please try again"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[restoreTransactionAlert show];
}
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
}
- (void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error
{
}
答案 0 :(得分:1)
恢复交易的实施不正确。您在-restoreTransactionsCompleted
方法中的条件,即
if (SKPaymentTransactionStatePurchased)
将始终返回true,因为SKPaymentTransactionStatePurchased是值为1的枚举。
查看有关恢复交易的文档here。