Check if an Auto-Renewable Subscription is still valid

前端 未结 4 1779
春和景丽
春和景丽 2020-12-09 04:15

I would like to check the Auto Renewable Subscription status whenever I open the app.

This is to make sure that the user is still subscribed to the service. How do I

4条回答
  •  孤街浪徒
    2020-12-09 04:54

    Yet another solution to handle auto-renewable iOS subscription using Qonversion SDK.

    AppDelegate.swift

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        Qonversion.launch(withKey: "yourProjectKey")
        
        
        return true
      }
    

    Get subscription status

    Link App Store subscription to Qonversion Product, and link the Product to Permission. Then you just need to trigger checkPermissions method at the start of your app to check if a user's subscription is still valid. This method will check the user receipt and will return the current permissions. And then for the still-active subscription, you can get the details if the subscriber has turned-off auto-renewal, if he is in grace period (billing retry state), etc.

    Qonversion.checkPermissions { (permissions, error) in
      if let error = error {
        // handle error
        return
      }
      
      if let premium = permissions["premium"], premium.isActive {
        switch premium.renewState {
           case .willRenew, .nonRenewable:
             // .willRenew is the state of an auto-renewable subscription 
             // .nonRenewable is the state of consumable/non-consumable IAPs that could unlock lifetime access
             break
           case .billingIssue:
             // Grace period: permission is active, but there was some billing issue.
             // Prompt the user to update the payment method.
             break
           case .cancelled:
             // The user has turned off auto-renewal for the subscription, but the subscription has not expired yet.
             // Prompt the user to resubscribe with a special offer.
             break
           default: break
        }
      }
    }
    

    You can check our sample app that demonstrates auto-renewable subscription implementation here.

提交回复
热议问题