Skip to content

Instantly share code, notes, and snippets.

@rkotzy
Last active December 30, 2020 01:42
Show Gist options
  • Save rkotzy/6026dd9a3c5421aa952e3c3987a0391e to your computer and use it in GitHub Desktop.
Save rkotzy/6026dd9a3c5421aa952e3c3987a0391e to your computer and use it in GitHub Desktop.
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