为非续订订阅恢复未处理的 SKPaymentTransaction
Restoring unprocessed SKPaymentTransaction for non-renewing subscription
我想在我的应用中实现非续订订阅。我已经建立(我相信是正确的)我的逻辑。我将观察者放在应用程序委托中,然后在实现 SKPaymentTransactionObserver
的 class 中,我实现了以下功能:
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) { }
在这个方法中,我遍历所有 updatedTransactions
并检查每个 transactionState
,并相应地实现我的逻辑。
让我烦恼的是:当交易成功时,我必须联系我们的服务器来更新用户的个人资料,并为 his/her 订阅增加更多天数。这意味着我必须在 SKPaymentQueue.default().finishTransaction(transaction)
收到服务器的成功响应后调用。但是,从 Apple 服务器发送交易已完成的那一刻起,直到我们的服务器响应,可能会出现问题。
一种捷径是在 Apple 响应后立即将交易标记为已完成,但通过阅读文档,这似乎并不正确。如何恢复未处理的交易? (如果我们的服务器没有响应并且 SKPaymentQueue.default().finishTransaction(transaction)
没有被调用)。
提前致谢。
只有在您的服务器确认交易后,您才应将交易标记为已完成。
如果在交易成功但您的服务器尚未发现期间确实出现问题(假设发生崩溃),交易将保持不完整状态,并且可以在 SKPaymentQueue.default.transactions
之后立即访问您将观察者添加到队列中。
然后您可以抓取这些交易或收据并将其发送到您的服务器,以再次尝试延长他们的订阅期限。
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.
我想在我的应用中实现非续订订阅。我已经建立(我相信是正确的)我的逻辑。我将观察者放在应用程序委托中,然后在实现 SKPaymentTransactionObserver
的 class 中,我实现了以下功能:
func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) { }
在这个方法中,我遍历所有 updatedTransactions
并检查每个 transactionState
,并相应地实现我的逻辑。
让我烦恼的是:当交易成功时,我必须联系我们的服务器来更新用户的个人资料,并为 his/her 订阅增加更多天数。这意味着我必须在 SKPaymentQueue.default().finishTransaction(transaction)
收到服务器的成功响应后调用。但是,从 Apple 服务器发送交易已完成的那一刻起,直到我们的服务器响应,可能会出现问题。
一种捷径是在 Apple 响应后立即将交易标记为已完成,但通过阅读文档,这似乎并不正确。如何恢复未处理的交易? (如果我们的服务器没有响应并且 SKPaymentQueue.default().finishTransaction(transaction)
没有被调用)。
提前致谢。
只有在您的服务器确认交易后,您才应将交易标记为已完成。
如果在交易成功但您的服务器尚未发现期间确实出现问题(假设发生崩溃),交易将保持不完整状态,并且可以在 SKPaymentQueue.default.transactions
之后立即访问您将观察者添加到队列中。
然后您可以抓取这些交易或收据并将其发送到您的服务器,以再次尝试延长他们的订阅期限。
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.