Files
safe-ios/Multisig/App/AppDelegate+Messaging.swift
Dirk JäckelandGitHub 17b4537284 gh-3055 Bump Intercom lib to 14.+ (#3082)
* gh-3055 Bump Intercom lib to 14.+

* gh-3055 Remove unneeded import. Show error when devicetoken cannot be set in Intercom

* gh-3055 Make everything static

* gh-3055 Remove intercom instance
2023-04-27 09:29:54 +02:00

60 lines
2.1 KiB
Swift

//
// AppDelegate+Messaging.swift
// Multisig
//
// Created by Dmitry Bespalov on 05.08.20.
// Copyright © 2020 Gnosis Ltd. All rights reserved.
//
import Foundation
import UIKit
import UserNotifications
import Firebase
extension AppDelegate: UNUserNotificationCenterDelegate {
func userNotificationCenter(
_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let userInfo = notification.request.content.userInfo
Messaging.messaging().appDidReceiveMessage(userInfo)
LogService.shared.debug("PUSH: App is in foreground, willPresent notification with userInfo: \(userInfo)")
completionHandler([.alert, .badge, .sound])
}
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
Messaging.messaging().appDidReceiveMessage(userInfo)
if IntercomConfig.isIntercomPushNotification(userInfo) {
IntercomConfig.pushNotificationUserInfo = userInfo
}
if SafeDeploymentNotificationController.isSafeCreatedNotification(userInfo) {
SafeDeploymentNotificationController.handleSafeCreatedNotification(userInfo: userInfo)
} else {
LogService.shared.debug("PUSH: didReceive notification with userInfo: \(userInfo)")
App.shared.notificationHandler.received(notification: userInfo)
}
completionHandler()
}
}
extension AppDelegate: MessagingDelegate {
// Firebase calls it on every app restart.
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String?) {
if let token = fcmToken {
App.shared.notificationHandler.pushTokenUpdated(token)
} else {
LogService.shared.debug("Couldn't obtain fcmToken value")
}
}
}