Critical Moments Docs
Quick StartHomepageAccount
  • Documentation Home
  • What is Critical Moments?
  • Quick Start
  • Concepts Overview
  • Remote Control / Service
    • Host Config on Github Pages
  • Config File Structure
  • Demo App
  • Homepage & Account
  • ๐Ÿ“šGuides
    • Mobile App Toolbox: 13 Features Most Apps Need
    • Reduce App Churn with Notifications
    • Improve your App Store Rating
    • Feature Flags Guide
  • โฐNotifications
    • Intro to Notifications
    • Notifications Spec
    • Smart Delivery
    • Badges
  • ๐ŸŽฏConditional Targeting
    • Intro to Conditions
    • Built-in Properties
    • Custom Properties
    • Syntax and Operators
    • Conditional Guides
      • Working with Dates
      • Locations and Weather
      • Event and Property History
  • ๐ŸŽชEvents
    • Event Overview
    • Recommended Events
    • Built-In Events
  • ๐Ÿ’ฌActions / In App Messaging
    • Actions Overview
    • Modals
      • Modal Content Sections
      • Modal Buttons
      • Modal Images
    • Banners
    • Alerts
    • App Reviews
    • Open Link
    • Custom Actions
    • Conditional Actions
    • Triggers
  • ๐ŸŽจThemes
    • Theme Overview
    • Built In Themes
  • โ›ณFeature Flags
    • Feature Flag Guide
    • Conditional Feature Flags
    • Named Conditions Config
  • ๐Ÿ”‘Trustless SaaS
  • ๐Ÿ‘‹Support
  • ๐Ÿ‘ฉโ€๐Ÿ’ปSDK API Reference
Powered by GitBook
On this page
  • Install the SDK ๐Ÿ”ง
  • Create your config file ๐Ÿ“„
  • Integrate the SDK into your app ๐Ÿงฉ
  • Update Your Info.plist
  • Test the Integration ๐Ÿงช
  • Explore the Demo
  • Log important events (optional, recommended) ๐ŸŽช
  • Add custom properties (optional, recommended) ๐Ÿ“…
  • Setup a cloud config file โ˜๏ธ
  • Request Notification Permissions
  • Customize your Integration ๐Ÿ—๏ธ

Was this helpful?

Quick Start

Get up and running! ๐Ÿ‘Ÿ๐Ÿ‘Ÿ

Last updated 13 days ago

Was this helpful?

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.

Detailed steps for adding SPM package
  • Open your app project in Xcode. Click "File" > "Add Package Dependencies..."

  • Paste the following URL in the search box in the top right: https://github.com/criticalmoments/criticalmoments and select the Critical Moments package. We suggest leaving the default settings for dependency rules: (Branch=main). We only merge stable releases to our main branch.

  • Select your iOS app project in the "Add to Project..." dropdown

  • Click "Add Package"

  • Select your iOS app target in the "Add to Target" dropdown

  • Click "Add Package"

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 (), 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 "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:

import CriticalMoments

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

CriticalMoments.shared().setDevelopmentConfigName("cmDevConfig.json")
// We'll add this later. This must be set before releasing app.
// CriticalMoments.shared().setReleaseConfigUrl("YOUR_URL")
CriticalMoments.shared().start()

In App Delegate imports section add:

@import CriticalMoments;

In App Delegate application:didFinishLaunchingWithOptions: add:

[CriticalMoments.shared setDevelopmentConfigName:@"cmDevConfig.json"];
// We will fill this in during a later step. This must be set before releasing to app store
// [CriticalMoments.shared setReleaseConfigUrl:@"YOUR_URL"];
[CriticalMoments.shared start];

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:

bash <(curl -fsSL https://raw.githubusercontent.com/CriticalMoments/CriticalMoments/refs/heads/vnext/ios/tools/setup_tool/setup_cm.sh)
Manual Instructions

Don't like magic scripts? We get that. You can also update the Info.plist manually.

Part 1: Enable Processing For Smart Notifications

Part 2: Set Bluetooth Reason String

Some optional properties like has_bt_headphones and bluetooth_permission use the system's bluetooth APIs. These won't be called unless you include them in your config. However Apple will detect them, and want a description in the Info.plist file.

Add an entry for NSBluetoothAlwaysUsageDescription to your Info.plist describing your bluetooth usage. If you app uses bluetooth directly, keep the description you have. If you don't otherwise use bluetooth, add a general description, such as "Used to show messages when not using peripherals".

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.

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.

CriticalMoments.shared().sendEvent("completed_game_level")
[CriticalMoments.shared sendEvent:@"completed_game_level"];

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.

try? CriticalMoments.shared().setIntegerProperty(42, forKey: "max_game_level")
[CriticalMoments.shared registerIntegerProperty:42 
               forKey:@"max_game_level" 
               error:nil];

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.

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.

CriticalMoments.shared().requestNotificationPermission()
[CriticalMoments.shared
        requestNotificationPermissionWithCompletionHandler:nil];

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:

Update Your Info.plist

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 .

Explore the Demo

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.

Request Notification Permissions

Download our . Our describes how each works, and how to enable them.

Read our to understand all the tools at your disposal.

๐Ÿ“”
๐Ÿ”ญ
๐Ÿ“ฌ
link
smart notifications
Apple guide
Apple guide
events documentation
custom properties documentation
Remote Control Docs
starter template with 13 features most apps need
blog post
Concepts Overview