Skip to content

iOS Integration

Integrate Entrig in 5 steps:

Install → Setup → Initialize → Register → Handle


Requirements

  • iOS 14.0+
  • Xcode 13.0+
  • Swift 5.5+

Installation

Swift Package Manager — in Xcode: File > Add Package Dependencies, enter:

https://github.com/entrig/entrig-ios.git

Select version 1.0.0.


Setup

Xcode

In Xcode, select your target > Signing & Capabilities:

  • Add Push Notifications capability
  • Add Background Modes capability > enable Remote notifications

AppDelegate

Configure Entrig and forward the required APNs callbacks in your AppDelegate:

import UIKit
import UserNotifications
import Entrig
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
// Initialize the SDK with your API key
Entrig.configure(config: EntrigConfig(apiKey: "YOUR_ENTRIG_API_KEY"))
// Required to receive foreground notification and tap callbacks
UNUserNotificationCenter.current().delegate = self
// Detects if the app was launched by tapping a notification (cold start)
Entrig.checkLaunchNotification(launchOptions)
return true
}
// Forwards the APNs device token to Entrig for registration
func application(_ application: UIApplication,
didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Entrig.didRegisterForRemoteNotifications(deviceToken: deviceToken)
}
// Forwards APNs registration failures to Entrig for error handling
func application(_ application: UIApplication,
didFailToRegisterForRemoteNotificationsWithError error: Error) {
Entrig.didFailToRegisterForRemoteNotifications(error: error)
}
}
extension AppDelegate: UNUserNotificationCenterDelegate {
// Called when a notification arrives while the app is in the foreground
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
Entrig.willPresentNotification(notification)
// Controls whether the notification banner is shown in foreground
completionHandler(Entrig.getPresentationOptions())
}
// Called when the user taps a notification from any app state
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
Entrig.didReceiveNotification(response)
completionHandler()
}
}

Your API key is available in the Entrig dashboard under project settings.


Registering Devices

Call Entrig.register() with the user’s ID when they sign in, and Entrig.unregister() when they sign out.

// On sign in
Entrig.register(userId: userId)
// On sign out
Entrig.unregister()

The userId you pass here must match the user identifier field configured in your notification in the Entrig dashboard. If they do not match, Entrig cannot resolve the recipient.

We recommend using the Supabase Auth user ID as the userId. It is stable, always available when using Supabase Auth, and is typically the ID that other tables in your database already reference.


Handling Notifications

When a notification arrives, your app can be in one of three states:

  • Foreground - app is open and visible
  • Background - app is running but not visible
  • Terminated - app is fully closed

Entrig handles displaying notifications in all three states. The only thing you need to handle is what happens when the user taps a notification.

To handle notification taps, conform to OnNotificationClickListener:

class MyViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
Entrig.setOnNotificationOpenedListener(self)
}
}
extension MyViewController: OnNotificationClickListener {
func onNotificationClick(_ notification: NotificationEvent) {
// navigate based on notification.type or notification.data
}
}

If the app was fully terminated when the notification was tapped, the listener may not be registered in time. Use getInitialNotification() on startup instead:

if let notification = Entrig.getInitialNotification() {
// app was launched by tapping a notification
// returns nil after being called once
}

By default, notifications are also shown as a banner when the app is in the foreground. You can turn this off:

Entrig.configure(config: EntrigConfig(
apiKey: "YOUR_ENTRIG_API_KEY",
showForegroundNotification: false
))

NotificationEvent fields:

FieldDescription
titleNotification title
bodyNotification body
typeCustom type identifier set in the dashboard
dataCustom payload data from your database

Permission Handling

By default, register() requests notification permission automatically. To handle permissions yourself:

let config = EntrigConfig(apiKey: "YOUR_ENTRIG_API_KEY", handlePermission: false)
Entrig.configure(config: config)
// Then request manually before registering
Entrig.requestPermission { granted, error in
if granted {
Entrig.register(userId: userId)
}
}