gpt4 book ai didi

ios - 为非续订订阅恢复未处理的 SKPaymentTransaction

转载 作者:行者123 更新时间:2023-11-28 10:48:41 25 4
gpt4 key购买 nike

在我的应用程序中,我想实现非续订订阅。我已经建立(我相信是正确的)我的逻辑。我将观察者放在应用程序委托(delegate)中,然后放在实现 SKPaymentTransactionObserver 的类中,我实现了以下功能:

func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) { }

在这个方法中,我循环遍历所有 updatedTransactions 并检查每个 transactionState,并相应地实现我的逻辑。

让我烦恼的是:交易成功后,我必须联系我们的服务器以更新用户的个人资料并为他/她的订阅添加更多天数。这意味着我必须调用 SKPaymentQueue.default().finishTransaction(transaction)我收到来 self 们服务器的成功响应。但是,从 Apple 的服务器发送交易已完成的那一刻起,直到我们的服务器响应,可能会出现问题。

一个快捷方式是在 Apple 响应后立即将交易标记为已完成,但通过阅读文档,这似乎并不正确。如何恢复未处理的交易? (如果我们的服务器没有响应并且 SKPaymentQueue.default().finishTransaction(transaction) 没有被调用)。

提前谢谢你。

最佳答案

只有在您的服务器确认交易后,您才应将交易标记为已完成。

如果在交易成功但您的服务器还没有看到它的时间之间出现问题(假设发生崩溃),交易将保持不完整,并且可以在 SKPaymentQueue.default.transactions< 中访问 在将观察者添加到队列之后。

然后,您可以获取这些交易或收据并将其发送到您的服务器,以再次尝试延长他们的订阅期限。

此外,from Apple's docs :

For example, consider the case of a user buying something in your app right before going into a tunnel. Your app isn’t able to deliver the purchased content because there’s no network connection. The next time your app is launched, StoreKit calls your transaction queue observer again and delivers the purchased content at that time. Similarly, if your app fails to mark a transaction as finished, StoreKit calls the observer every time your app is launched until the transaction is properly finished.

关于ios - 为非续订订阅恢复未处理的 SKPaymentTransaction,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47197148/

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