Last active
December 30, 2020 01:42
-
-
Save rkotzy/6026dd9a3c5421aa952e3c3987a0391e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import Purchases | |
class CatsViewController: UIViewController { | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// 1. Add an observer for our kPurchaserInfoUpdated notification that triggers a function to update the view | |
NotificationCenter.default.addObserver(self, | |
selector: #selector(updateViewForPurchaserInfo), | |
name: NSNotification.Name("kPurchaserInfoUpdated"), object: nil) | |
updateViewForPurchaserInfo() | |
} | |
// 2. Create a function that will update the state of your view based on the PurchaserInfo status | |
@objc func updateViewForPurchaserInfo() { | |
Purchases.shared.purchaserInfo { (purchaserInfo, error) in | |
self.configureCatContentFor(purchaserInfo: purchaserInfo) | |
} | |
} | |
func configureCatContentFor(purchaserInfo: Purchases.PurchaserInfo?) { | |
// set the content based on the user subscription status | |
} | |
// 3. Remove the observer when the view is deallocated | |
deinit { | |
NotificationCenter.default.removeObserver(self) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment