gpt4 book ai didi

ios - 恢复应用内购买错误 : restores even if not purchased

转载 作者:行者123 更新时间:2023-12-02 04:53:05 26 4
gpt4 key购买 nike

一位(诚实的)用户刚刚告诉我,即使尚未购买应用内购买,只需按“恢复”按钮即可“购买”我的应用程序的应用内购买。这是我正在使用的代码(我认为这已经足够了......但我错了):

 - (IBAction) restore {

[[SKPaymentQueue defaultQueue] addTransactionObserver:self];
[[SKPaymentQueue defaultQueue] restoreCompletedTransactions];
}


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

for (SKPaymentTransaction *transaction in transactions) {

switch(transaction.transactionState){

case SKPaymentTransactionStatePurchasing:

NSLog(@"Transaction state -> Purchasing ...");

break;

case SKPaymentTransactionStatePurchased:

NSLog(@"Transaction state -> Purchased");

[self activatePurchase];

[[SKPaymentQueue defaultQueue] finishTransaction:transaction];

break;

case SKPaymentTransactionStateRestored:

NSLog(@"Transaction state -> Restored");

[[SKPaymentQueue defaultQueue] finishTransaction:transaction];


break;

case SKPaymentTransactionStateFailed:

NSLog(@"Transaction state -> Cancelled");

if(transaction.error.code == SKErrorPaymentCancelled) {

//the user cancelled the payment ;(
}

[[SKPaymentQueue defaultQueue] finishTransaction:transaction];

break;

case SKPaymentTransactionStateDeferred:

NSLog(@"Transaction state -> Deferred");

break;
}
}
}




- (void) paymentQueueRestoreCompletedTransactionsFinished:(SKPaymentQueue *)queue {

[self activatePurchase];

}

我有什么遗漏的吗?

最佳答案

付款观察者方法 paymentQueueRestoreCompletedTransactionsFinished 会在付款队列完成恢复交易时调用,无论是否实际恢复了任何交易。每次调用 restoreCompletedTransactions 时,您都会收到一次对 paymentQueueRestoreCompletedTransactionsFinished 的调用,即使对 updatedTransactions 的调用次数为 0 次。

因此,即使没有购买,您也会调用 activatePurchase

激活购买的正确位置是 updateTransactions 中的 SKPaymentTransactionStateRestored 案例;就像您对 SKPaymentTransactionStatePurchased 案例所做的那样。

关于ios - 恢复应用内购买错误 : restores even if not purchased,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38467354/

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