I wanted to offer an alternative solution that uses Profitable SDK for those who are still faced with this issue.
AppDelegate.swift
Configure the RevenueCat SDK for purchases with your API key and optional user ID.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { Purchases.configure(withAPIKey: "<...>", appUserID: "<...>") ... return true }
Subscription Status Feature
The function below checks the PurchaserInfo parameter to see if the user has an active βrightβ (or you can directly check the active product identifier).
func subscriptionStatus(completion: @escaping (Bool)-> Void) { Purchases.shared.purchaserInfo { (info, error) in // Check if the purchaserInfo contains the pro feature ID you configured completion(info?.activeEntitlements.contains("pro_feature_ID") ?? false) // Alternatively, you can directly check if there is a specific product ID // that is active. // completion(info?.activeSubscriptions.contains("product_ID") ?? false) } }
Obtaining a subscription status
You can call the above function as often as necessary, since the result is cached by the SDK for purchases, in most cases it will be returned synchronously and does not require a network request.
override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) subscriptionStatus { (subscribed) in if subscribed { // Show that great pro content } } }
If you use SwiftyStoreKit, the syntax of RevenueCat is pretty similar, and there is a migration guide to help switch.
source share