应用程序购买中的自动续订订阅

时间:2016-02-23 06:14:45

标签: ios objective-c swift in-app-purchase

我正在开展一项项目,因为我需要自动续订订阅。我完成了后端工作,但现在我怀疑是," h 来获取订阅状态。如果用户在续订订阅之前取消或关闭自动续订"。请帮忙。

2 个答案:

答案 0 :(得分:1)

您需要解析应用内购买的收据以检查到期日期。您可以自己从NSBundle.mainBundle().appStoreReceiptURL解析它,也可以将其发送给Apple并从JSON响应中解析它。见Receipt Validation guide

答案 1 :(得分:0)

我已经实施了一个小型库,以简化在本地使用应用内收据。您可以轻松获取代表收据的对象(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)
}