Unlock content / service

On paywall displayed

When you display a paywall with Purchasely.presentation you have a closure for the result of user action PLYProductViewControllerResult with three possible values

  • Purchased

  • Restored

  • Cancelled

You also have as a second argument the plan bought or restored by the user, it is set to nil if no purchase was made. This is the preferred way to get notified when a purchase or restoration was made from a Purchasely paywall.

let paywallCtrl = Purchasely.presentationController(
   for: "my_placement_id",
   contentId: "my_content_id",
   completion: { (result, plan) in
	switch result {
                case .purchased:
                    print("User purchased: \(plan?.name)")
                    break
                case .restored:
                    print("User restored: \(plan?.name)")
                    break
                case .cancelled:
                    break
                @unknown default:
                    break
	}												
})

Anywhere in your application

When a purchase or restoration is made, you can listen to our notification. This is the method to use in parts of your application where you wish to unlock some features after a purchase was made but you should only use it to unlock content, not to notify your server of a purchase or check the current state of user subscription. Once the purchase is made to Apple Servers, registered in our systems, Purchasely sends a local Notification in the NotificationCenter. You can use it to unlock the content or refresh it.

You can catch it like this

 NotificationCenter.default.addObserver(self, selector: #selector(reloadContent(_:)), name: .ply_purchasedSubscription, object: nil)

And use it like that

 @objc func reloadContent(_ notification: Notification) {
     // Reload the content
 }

For example, this can be done in every controller that displays premium content. That way you won't have to reload the content each time the controller is displayed unless a payment was made

Last updated

© Purchasely 2020-2023