This app demonstrates how to use SuperwallKit with UIKit. We've written a mini tutorial below to help you understand what's going on in the app.
Usually, to integrate SuperwallKit into your app, you first need to have configured a paywall using the Superwall Dashboard. However, with this example app, we have already done that for you and provided a sample API key to get you up and running. When you integrate the SDK into your own app, you'll need to use your own API key for your own Superwall account. To do that, sign up for a free account on Superwall.
Feature | Sample Project Location |
---|---|
🕹 Configuring SuperwallKit | AppDelegate.swift |
👉 Presenting a paywall | HomeViewController.swift |
👥 Identifying account | WelcomeViewController.swift |
👥 Resetting account | HomeViewController.swift |
This example app uses:
- UIKit
- Xcode 14
- iOS 16
- Swift 5.5
Clone or download SuperwallKit from the project home page. Then, open Superwall-UIKit-Swift.xcodeproj in Xcode and take a look at the code inside the Superwall-UIKit-Swift folder.
You'll see a few folders relating to the design and components used in the app, which you don't need to worry about.
The AppDelegate.swift handles the configuration of the SDK. WelcomeViewController.swift is handles login and HomeViewController.swift handles the presentation of paywalls.
Superwall_UIKit-Swift-Products.storekit is a StoreKit configuration file that is used to mimic the setup of real products on App Store Connect. This is so you can make test purchases within the sample app without having to set up App Store Connect. In a production app, you will need real products configured in App Store Connect but you can also use a StoreKit configuration file for testing purposes if you wish.
You'll see Main.storyboard specifies the the layout of the app.
Build and run the app and you'll see the welcome screen:
SuperwallKit is configured on app launch, setting an apiKey
.
On the welcome screen, enter your name in the text fieldThis saves to the Superwall user attributes using Superwall.shared.setUserAttributes(_:). You don't need to set user attributes, but it can be useful if you want to create a rule to present a paywall based on a specific attribute you've set. You can also recall user attributes on your paywall to personalise the messaging.
Tap Log In. This identifies the user (with a hardcoded userId that we've set), retrieving any paywalls that have already been assigned to them.
You'll see the home screen:
At the heart of Superwall's SDK lies Superwall.shared.register(event:params:handler:feature:).
This allows you to register an event to access a feature that may or may not be paywalled later in time. It also allows you to choose whether the user can access the feature even if they don't make a purchase. You can read more about this in our docs.
On the Superwall Dashboard you add this event to a Campaign and attach some presentation rules. For this app, we've already done this for you.
When an event is registered, SuperwallKit evaluates the rules associated with it to determine whether or not to show a paywall.
By calling Superwall.shared.register(event:params:handler:feature:), you present a paywall in response to the event campaign_trigger
.
On screen you'll see some explanatory text and a button to launch a feature that is behind a paywall:
Tap the Launch Feature button and you'll see the paywall. If the event is disabled on the dashboard, the paywall wouldn't show and the feature would fire immediately. In this case, the feature is just an alert.
Tap the Continue button in the paywall and "purchase" a subscription. When the paywall dismisses, the "feature" is launched and you'll see an alert. Try launching the feature again. You'll notice that the feature is fired immediately and no longer shows the paywall. Paywalls are only presented to users who haven't got an active subscription. To cancel the active subscription for an app that's using a StoreKit configuration file for testing, delete and reinstall the app.
For an in-depth explanation of how to use SuperwallKit, visit our online docs.
For a technical reference, view our iOS SDK documentation. If you'd like to view it in Xcode, select Product ▸ Build Documentation.