SDK Implementation

The only required steps to get started with Purchasely

This is a simplified overview of our SDK implementation, you can find a more detailed one in SDK configurations section

Configuration

The start method must be called as soon as possible to catch every purchase / renewal.

import Purchasely

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    Purchasely.start(withAPIKey: "API_KEY,
                         appUserId: nil,
			 runningMode: .full,
			 eventDelegate: nil,
			 storekitSettings: .storeKit1, // Set your StoreKit version
			 logLevel: .debug) { (success, error) in
		print(success)
        }
	return true
}

The userID parameter is optional and allows you to associate the purchase to a user instead of a device.

If you want to use StoreKit 2, please make sure that you have followed all required steps first

Display a placement

Paywalls are displayed by calling a Placement.

A Placement represents a specific location in your user journey inside your app (e.g. Onboarding, Settings, Home page, Article). A placement is linked to a paywall and a single paywall can be used for different Placements. You can create as many Placements as you want, and this is the only thing that ties the app developer to the marketer.

Once the placements are defined and called from the app, you can change the displayed paywall remotely without any developer action.

You can also preload paywalls asynchronously using fetchPresentation method

let placementId = "ONBOARDING"
paywallCtrl = Purchasely.presentationController(for: placementId, contentId: contentId, loaded: { _, _, _ in
            }, completion: completion)

Unlock content

With the method to display a placement, you get the result of the user action on the paywall.

  • Cancelled: User did not purchase a plan

  • Restored: User restored a previous purchased plan

  • Purchased: User purchased a plan which was validated by the store and your webhook

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.

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
	}												
})

Last updated

© Purchasely 2020-2023