Skip to main content
Version: 4.38.0

Configuring Notifications

After the initial initialization is complete, you need to add the following SDK calls to enable push notifications:

// MARK: - Remote Notifications

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Threads.threads().applicationDidRegisterForRemoteNotifications(withDeviceToken: deviceToken)
}

// MARK: - UNUserNotificationCenterDelegate

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
// Check for application launched from notification
if response.actionIdentifier == UNNotificationDefaultActionIdentifier {
let userInfo = response.notification.request.content.userInfo
if Threads.threads().isThreadsOriginPushUserInfo(userInfo) {
// Application launched from Threads notification
} else {
// Application launched from other notifications
}
}
completionHandler()
}

Integration with Push Lite

note

This section is only relevant for projects that already use the push-lite SDK to deliver notifications.

To configure and integrate push-lite, follow the instructions provided with the SDK.

Initialization of the Chat Center library must go first:

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

// Step 1: Configure Threads Framework
let threads = Threads.threads()
threads.registrationAtStartupDisable = SettingsBundleHelper.getRegistrationAtStartupDisable()
threads.isClientIdEncrypted = Configuration.clientIdEncrypted()

threads.isShowsNetworkActivity = true

guard let providerUid = Configuration.providerUid() else { fatalError("Set providerUid for threadsGate transportProtocol.") }
threads.configureTransportProtocol(
with: self,
webSocketURL: URL(string: Configuration.webSocketURL())!,
providerUid: providerUid,
restURL: URL(string: Configuration.restServerURL())!,
dataStoreURL: URL(string: Configuration.dataStoreURL())!
)

// Step 2: Configure PushLite Framework
pushLite = EDNAPushLite(delegate: self)
pushLite.appGroup = "group.io.edna.chatcenter.demo"
pushLite.autoRegisterForNotification = false
pushLite.logEnable = true
pushLite.start()

// Step 3: Register device for remote notifications
...

return true
}

The values from the notification delegates are passed in the same order:

    func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Threads.threads().applicationDidRegisterForRemoteNotifications(withDeviceToken: deviceToken)
pushLite.appDelegate.didRegisterForRemoteNotifications(withDeviceToken: deviceToken)
}

func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
pushLite.appDelegate.didFailToRegisterForRemoteNotifications(withError: error)
}