【发布时间】:2017-01-24 12:17:51
【问题描述】:
我正在开发一个需要自动续订订阅的项目。我已经完成了后端工作,但现在我的疑问是,“如何获得订阅状态。如果用户在续订订阅之前取消或关闭自动续订”。请帮忙。
【问题讨论】:
标签: ios objective-c swift in-app-purchase
我正在开发一个需要自动续订订阅的项目。我已经完成了后端工作,但现在我的疑问是,“如何获得订阅状态。如果用户在续订订阅之前取消或关闭自动续订”。请帮忙。
【问题讨论】:
标签: ios objective-c swift in-app-purchase
您需要解析应用内购买的收据以检查到期日期。您可以自己从NSBundle.mainBundle().appStoreReceiptURL 解析它,或者您可以将其发送到苹果并从 JSON 响应中解析它。见Receipt Validation guide
【讨论】:
我已经实现了一个小型库来简化在本地使用应用内收据。您可以轻松获取代表收据 (InAppReceipt) 的对象并检索有效购买/所有购买。
请随意使用。 Github link
以下是解决问题的示例:
import TPInAppReceipt
do {
let receipt = try InAppReceiptManager.shared.receipt()
//retrive active auto renewable subscription for a specific product and date
let purchase = receipt.activeAutoRenewableSubscriptionPurchases(ofProductIdentifier: "ProductName", forDate: Date())
//retrive all auto renewable subscription purchases for a specific product
let allAutoRenewableSubscriptionPurchases = receipt.purchases(ofProductIdentifier: "productName").filter({ return $0.isRenewableSubscription })
} catch {
print(error)
}
【讨论】: