Перейти к основному содержимому
Версия: 4.31.0

Настройка уведомлений

После завершения первоначальной инициализации, необходимо добавить следующие вызовы SDK для подключения push уведомлений:

// 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()
}

Интеграция с Push Lite

примечание

Этот раздел актуален только для проектов, в которых уже используется SDK push-lite для доставки уведомлений.

Для настройки и интеграции push-lite следуйте инструкциям предоставляемым вместе с SDK

Инициализация библиотеки Threads должна идти первой

    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
}

В таком же порядке передаются значения из делегатов нотификации

    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)
}