gpt4 book ai didi

ios - 如何在 iOS 中恢复非消耗品的 IAP

转载 作者:行者123 更新时间:2023-11-29 11:31:07 25 4
gpt4 key购买 nike

我想知道是否必须将两个按钮分开,一个用于升级,另一个用于恢复以恢复以前的交易?

我自己应该采取什么步骤来避免 App for Restore 交易被拒绝的机会。

我使用以下代码恢复非消耗性应用内购买。如果以下代码有任何更改,请告诉我。

- (void)buyProduct:(SKProduct *)product {

[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
//[[SKPaymentQueue defaultQueue] addPayment:payment];
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];

}

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions
{

for (SKPaymentTransaction * transaction in transactions) {

switch (transaction.transactionState)
{
// Call the appropriate custom method for the transaction state.
case SKPaymentTransactionStatePurchasing:
[self showTransactionAsInProgress:transaction deferred:NO];
break;
case SKPaymentTransactionStateDeferred:
[self showTransactionAsInProgress:transaction deferred:YES];
break;
case SKPaymentTransactionStatePurchased:
[self completeTransaction:transaction];
break;
case SKPaymentTransactionStateFailed:
[self failedTransaction:transaction];
break;
case SKPaymentTransactionStateRestored:
[self restoreTransaction:transaction];
default:
// For debugging
NSLog(@"Unexpected transaction state %@", @(transaction.transactionState));
break;
}
};


}

- (void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error
{
NSLog(@"Restore Completed Transactions Failed WithError...%@",error);
[self failedMessage:@"Restore Completed Transactions Failed"];
[self stopIndicator];
}

- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue
{
NSMutableArray *arrPurchasedItemIDs = [[NSMutableArray alloc] init];
for (SKPaymentTransaction *transaction in queue.transactions)
{
NSString *productID = transaction.payment.productIdentifier;

[arrPurchasedItemIDs addObject:productID];

NSLog(@"arrPurchasedItemIDs : %@",arrPurchasedItemIDs);
}

NSLog(@"Restore Completed");
[self completeMessage:@"Restore Completed"];
[self stopIndicator];
}

最佳答案

这里如何分离恢复购买代码:

-(void)doClickRestore {
[APP_DEL doStartSpinner];
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}

-(void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions {
for (SKPaymentTransaction *transaction in transactions) {
switch (transaction.transactionState) {
// Purchase success Transaction
case SKPaymentTransactionStatePurchased:
[self completeTransaction:transaction];
break;
// Purchase fail Transaction
case SKPaymentTransactionStateFailed:
[self failedTransaction:transaction];
break;
case SKPaymentTransactionStateRestored:
{
[self doStopSpinner];
[self restoreTransaction:transaction];
}
default:
break;
}
}
}

- (void) restoreTransaction: (SKPaymentTransaction *)transaction {
[self doStopSpinner];
[[SKPaymentQueue defaultQueue] finishTransaction: transaction];
}

注意:

点击恢复购买将恢复所有已购买的非消耗性应用内购买

希望对您有所帮助。

下面这两个方法是可选的,但如果你愿意,你可以使用它。

- (void)paymentQueue:(SKPaymentQueue *)queue restoreCompletedTransactionsFailedWithError:(NSError *)error 


- (void)paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue

关于ios - 如何在 iOS 中恢复非消耗品的 IAP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53518814/

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