Quick Start
Get up and running! ๐๐
Let's get you started! This guide will walk you through the most important steps
Install the SDK ๐ง
Our iOS SDK is distributed as as a SPM package (Swift Package Manager). Simply add a SPM dependency in Xcode on https://github.com/criticalmoments/criticalmoments
.
Create your config file ๐
The CM config file defines how the SDK integrates into your app. Let's get started with a template integration:
Download our template
cmDevConfig.json
(link), which includes a demo of our features on launch. We'll remove the demo later, but it's helpful to test the integration.Set the appId on the 3rd line to your app's bundle ID.
Add the file to your Xcode project.
Integrate the SDK into your app ๐งฉ
Add the following code snippet into your app.
Put it somewhere that will run right after app startup, such as AppDelegate.didFinishLaunchingWithOptions
Replace the
YOUR_API_KEY
string an API key you created in your account.Replace
"cmDevConfig.json"
if you used a different name for the config file.The console will show a warning for now, but this will be resolved in a later step of this guide
In your App Delegate imports add:
Add the following code to your app launch. The location depends on the type of app you have:
App Delegate based apps, call from
application(_:didFinishLaunchingWithOptions:)
SwiftUI lifecycle apps, call from
YourApp.init
Startup work will be dispatched to background threads, and will not impact your app's startup time.
Update Your Info.plist ๐
Critical Moments requires a few updates to your Info.plist file. We've made a script to make this easy. Run the following command in your project folder in terminal, and then follow the instructions. It will explain the changes it's making, and won't make any changes until you confim:
Test the Integration ๐งช
Launch your app. If the integration is working, you should see a CM demo when the app starts; this demo was included in the template file you downloaded earlier.
If there are any issues, check the logs. When running a debug build, Critical Moments will log any issues preventing the SDK from working.
Note: while CM now works in debug mode, more steps below are needed before releasing to the App Store.
Explore the Demo ๐ญ
Try out the demo to see each feature of the SDK integrated into your app. To re-lauch the demo, simply restart the app.
Once your done with the demo, you can delete the demo content in cmDevConfig.json
; just be sure leave the configVersion
and appId
json entries.
This demo is implemented entirely in config
It shows how you can add many features to your app without writing code, including fully native UI, integrations into native APIs, powerful conditions, and notifications. If you're curious how any part of the demo works, simply read cmDevConfig.json
.
In a later step, we'll setup your app to update this config over-the-air, without app updates.
Log important events (optional, recommended) ๐ช
The more Critical Moments knows about your user's behaviours, the better you can target and optimize with Critical Moments.
We recommend you log important events, including the important actions your users performs in app. See the events documentation for the suggested events and details.
Add custom properties (optional, recommended) ๐
Properties are datapoints used in targeting. The more useful data you add, the more powerful the targeting system can be.
We recommend you add the important properties like account_creation_date, has_subscription, and others. See the custom properties documentation for suggested custom properties, and API reference.
Setup a cloud config file โ๏ธ
For local development you can use your local JSON config file built into the app binary. However, production builds must use a signed config file, hosted on the web.
Read the Remote Control Docs for the best practices of picking a hosting provider, signing, and deploying your config.
Once deployed, set the release config URL in your App Delegate, and uncomment the call to setReleaseConfigUrl("YOUR_URL")
.
You can test your app using the production config by running a "release" build instead of a "debug" build in XCode.
Update Anytime
Deploying the config file can be done outside of app releases, allowing you to update your apps behaviour without waiting for app reviews, or users to update their builds!
Request Notification Permissions ๐ฌ
If you ever want to show the user notifications, you'll need to ask the user for permission first.
Requesting permission with the Critical Moments helper method instead of the system requestAuthorization
method is beneficial as it will schedule any CM notifications after approval. An optional callback will be called after the user approves/denies notifications.
Customize your Integration ๐๏ธ
Remove the demo content from your copy of cmDevConfig.json
and start building using the powerful combination of conditionals, notifications, events, properties, feature flags, and actions!
Some good places to start and get ideas:
Download our starter template with 13 features most apps need. Our blog post describes how each works, and how to enable them.
Read our Concepts Overview to understand all the tools at your disposal.
Last updated