Skip to content

iOS SDK

Follow the guide below to enter the credentials FlareLane needs to send push notifications.

Go to your target's Signing & Capabilities, click + Capability in the top left, and add Push Notifications.

Then add Background Modes and enable Remote notifications.

Xcode Signing and Capabilities tab with Push Notifications and Background Modes enabled

On iOS, a Notification Service Extension is required to attach media such as images.

In Xcode, go to File > New > Target and select Notification Service Extension.

Xcode new target dialog with Notification Service Extension selected

Enter an appropriate name in Product Name. For this guide, we'll use FlareLaneNotificationServiceExtension.

Xcode new target configuration with FlareLaneNotificationServiceExtension as product name

Click Cancel so that no separate Scheme is activated.

Xcode dialog asking to activate a new scheme with Cancel highlighted

Next, set the Minimum Deployments version of the Notification Service Extension Target you just created to match the version of your main app target.

Xcode target Minimum Deployments setting for the Notification Service Extension

An App Group is required to sync data between the main app and the extension.

Go to your target's Signing & Capabilities, click + Capability in the top left, and add App Groups.

Add a group named group.bundleID.flarelane, where bundleID must match your main app's Bundle Identifier.

Xcode Signing and Capabilities with App Groups capability and flarelane group added

Once it has been added successfully, enable that App Group.

Xcode App Groups capability with the flarelane group enabled

Likewise, add and enable an App Group with the same name in the extension you created earlier.

Xcode extension target App Groups capability with the flarelane group enabled

Choose one of the two integration methods below, whichever best fits your project.

Open your Podfile and add the following.

// Add the line below at the top of the file to enable Dynamic Frameworks.
use_frameworks!
target 'YOUR_PROJECT_NAME' do
// Add the line below
pod 'FlareLane', '1.10.0'
end
// Add the line below at the bottom of the file.
// Set the target name to the Product Name of the extension you entered earlier.
target 'FlareLaneNotificationServiceExtension' do
pod 'FlareLane', '1.10.0'
end

Run pod install to finish installing the SDK.

Enter https://github.com/flarelane/FlareLane-iOS-SDK as the package URL, and set Exact Version to 1.9.3.

Xcode Swift Package Manager dialog with FlareLane iOS SDK URL and exact version entered

Select FlareLane for the main target, and FlareLaneExtension for the extension target.

Xcode SPM package product selection for FlareLane main and extension targets

5-1. (SwiftUI only) Create AppDelegate.swift

Section titled “5-1. (SwiftUI only) Create AppDelegate.swift”

SwiftUI projects don't include an AppDelegate.swift file, so you need to create one first.

Create a new AppDelegate.swift file and make a few changes to your existing <YOUR_PROJECT_NAME>App.swift file.

import UIKit
class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
return true
}
}
  1. Add the application(:didFinishLaunchingWithOptions:) method
  2. Add the application(:didRegisterForRemoteNotificationsWithDeviceToken:) method
import FlareLane
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// 1
// To control when the notification permission prompt appears, set the third parameter to false and call .subscribe() at the appropriate time.
FlareLane.initWithLaunchOptions(launchOptions, projectId: "PROJECT_ID", requestPermissionOnLaunch: true)
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
// 2
FlareLaneAppDelegate.shared.application(application, didRegisterForRemoteNotificationsWithDeviceToken: deviceToken)
}
}

5-3. Add UNUserNotificationCenterDelegate Methods

Section titled “5-3. Add UNUserNotificationCenterDelegate Methods”
  1. Set the AppDelegate as the UNUserNotificationCenterDelegate
  2. Add the userNotificationCenter(:willPresent:withCompletionHandler:) method
  3. Add the corresponding method
import FlareLane
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// 1
UNUserNotificationCenter.current().delegate = self
}
}
extension AppDelegate: UNUserNotificationCenterDelegate {
// 2
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
FlareLaneNotificationCenter.shared.userNotificationCenter(center, willPresent: notification, withCompletionHandler: completionHandler)
}
// 3
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
FlareLaneNotificationCenter.shared.userNotificationCenter(center, didReceive: response, withCompletionHandler: completionHandler)
}
}

5-4. Add UNNotificationServiceExtension Methods

Section titled “5-4. Add UNNotificationServiceExtension Methods”
  1. Add the didReceive(:withContentHandler:) method
  2. Add the serviceExtensionTimeWillExpire() method
import UserNotifications
import FlareLane
class NotificationService: UNNotificationServiceExtension {
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
// 1
// Branch the logic so that only FlareLane's methods run for push notifications sent by FlareLane.
if FlareLaneNotificationServiceExtensionHelper.shared.isFlareLaneNotification(request) {
FlareLaneNotificationServiceExtensionHelper.shared.didReceive(request, withContentHandler: contentHandler)
} else {
// ...
}
}
override func serviceExtensionTimeWillExpire() {
// 2
FlareLaneNotificationServiceExtensionHelper.shared.serviceExtensionTimeWillExpire()
}
}

When the app is installed, the device created in FlareLane is an "anonymous device." By linking the unique User ID that you manage separately, you can match FlareLane's device to your own User ID.

Linking a User ID has many benefits. It lets you distinguish between members and non-members, and lets you send push notifications by User ID at any time, so we recommend setting it up early in your integration.

Typically, you link the User ID through the setUserId function when a user signs up or logs in successfully.

FlareLane.setUserId(userId: "USER_ID")
  • FlareLane offers a variety of convenience features for WebView-based apps so that actions taken on the website can also be recognized in the app. See the WebView-based mobile app bridge guide.
  • By default, FlareLane automatically handles URLs such as https links and deep links when a push notification is clicked. If you need to implement your own click handler, see Disable Automatic URL Handling.
Guide
Mobile SDK Reference
iOS SDK Release Notes