在应用程序购买中使用自动续订订阅时需要恢复按钮吗?

Restore button is required when auto-renewable subscription used In App Purchase?

我在我的应用程序中使用了 auto-renewable subscription。一切正常,但如果用户从 iPhone 中删除应用程序并再次安装,那么如何知道该用户是否已订阅?

我们是否必须存储用户数据或服务器?

我提到了一些类似的问题,他们说 Apple 拒绝使用 auto-renewable In-App-Purchase.

恢复按钮的应用

你应该保留一个恢复按钮。

收据会告诉您是否订阅,您可以通过您的服务器验证这一点。了解信息

https://developer.apple.com/library/content/releasenotes/General/ValidateAppStoreReceipt/Chapters/ValidateRemotely.html

在那里你必须检查 latest_receipt_info 键,那将是 json 的数组然后你读取最后一个对象并检查 expires_date键。

https://developer.apple.com/library/content/releasenotes/General/ValidateAppStoreReceipt/Chapters/ReceiptFields.html#//apple_ref/doc/uid/TP40010573-CH106-SW2

他们拒绝没有恢复按钮的应用程序。每个提供 non_consumable 或 auto_renewable_subscription 购买的应用都必须拥有它。他们还提供您需要的一切,以便在 SKPaymentQueue 上实际恢复用户购买,而无需将其存储在其他地方。

SKPaymentQueue.default().restoreCompletedTransactions()

哪个会触发方法:

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

来自

SKPaymentTransactionObserver

我推荐这个指南,那里的一切都很好用:https://hackernoon.com/swift-how-to-add-in-app-purchases-in-your-ios-app-c1dc2fc82319

此外,在询问购买历史记录之前,请不要忘记添加您的商品 ID。