gpt4 book ai didi

ios - IAP 恢复按钮

转载 作者:行者123 更新时间:2023-11-29 12:39:36 28 4
gpt4 key购买 nike

我正在使用非消耗型 IAP 并尝试让恢复按钮正常工作。

我注意到,当用户尝试购买他们已经购买过的东西时,会出现一个 Apple 提醒,提示“您已经购买了这个。您想免费再次购买吗?”

所以我想知道如何为我的恢复按钮使用完全相同的收据验证方法/代码?

我好像找不到它的代码。我查看了 paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions 和其他地方?

你能帮忙吗?谢谢!

更新

- (IBAction)purchaseRestore:(id)sender {
[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue]restoreCompletedTransactions];
// Stack
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
NSLog(@"4 IBAction Purchase Restore Method");
}

更新 2我不知道我这样做是对的,是在某些代码上加倍,还是添加了不需要的代码。

-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
for (SKPaymentTransaction *transaction in transactions) {
switch (transaction.transactionState) {
case SKPaymentTransactionStatePurchasing:
NSLog(@"2 Payment Queue updatedTransactions - needs to verify logged in user: Purchasing Product From Store!");
break;
case SKPaymentTransactionStatePurchased:
if ([transaction.payment.productIdentifier
isEqualToString:INAPP_PRODUCT_ID_3]) {
NSLog(@"3 Payment Queue updatedTransactions - Product Purchased From Store!");
//Not sure if I need this
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:
@"3 Payment Queue updatedTransactions - Seems to to this twice: Purchase is completed succesfully" message:nil delegate:
self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[alertView show];

[self saveTransactionReceipt:transaction];
NSLog(@"3 Payment Queue updatedTransactions - Save Transaction Receipt: Called after product purchased");
[self saveValue:transaction];
NSLog(@"3 Payment Queue updatedTransactions - Save Value: Called after product purchased");
[self showButtonThree];
NSLog(@"3 Payment Queue updatedTransactions: will Show button Three now");

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setBool:YES forKey:@"purchasedThree"];
NSLog(@"updatedTransactions Yes for purchasedTeamThree: %hhd", [defaults boolForKey:@"purchasedThree"]);
[defaults synchronize];

[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
NSLog(@"3 Payment Queue finishTransaction: Run");
}
break;
case SKPaymentTransactionStateRestored:
NSLog(@"Restored");
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
purchaseButton.enabled = YES;
NSLog(@"2 Payment Queue updatedTransactions: Purchase failed ");
[[SKPaymentQueue defaultQueue] finishTransaction:transaction];
break;
default:
break;
}
}
}

最佳答案

你的问题实际上对我也很有用,因为你让我意识到我目前在 AppStore 审批过程中等待的应用程序可能会被拒绝,因为我没有实现恢复按钮(我只是添加了一个标签上写着再次按下购买按钮将恢复之前的购买)。

执行恢复过程的正确方法是实现一个调用此方法的按钮:

[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];

当然,在那之后,恢复仅限付费用户使用的应用功能。

希望这对您有所帮助。

关于ios - IAP 恢复按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25342864/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com