Quick Start
Get up and running! ๐๐
Last updated
Was this helpful?
Get up and running! ๐๐
Last updated
Was this helpful?
Let's get you started! This guide will walk you through the most important steps
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
.
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
(), 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.
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 .
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.
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:
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.
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.
The more Critical Moments knows about your user's behaviours, the better you can target and optimize with Critical Moments.
Properties are datapoints used in targeting. The more useful data you add, the more powerful the targeting system can be.
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.
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!
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.
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:
Features like require running your app to run in the background for brief periods, to check for ideal conditions. To setup background work:
In Xcode > project editor > Signing & Capabilities > Add (+) > Background Modes check the boxes for "Background fetch" and "Background processing". See .
In your Info.plist
add an array "Permitted background task scheduler identifiers" (BGTaskSchedulerPermittedIdentifiers
) with these two values: io.criticalmoments.bg_fetch
and io.criticalmoments.bg_process
. See .
We recommend you log important events, including the important actions your users performs in app. See the for the suggested events and details.
We recommend you add the important properties like account_creation_date, has_subscription, and others. See the for suggested custom properties, and API reference.
Read the for the best practices of picking a hosting provider, signing, and deploying your config.
Download our . Our describes how each works, and how to enable them.
Read our to understand all the tools at your disposal.