Когда приложение в фоновом режиме или неактивно, правильное нажатие на уведомление срабатывает:
Код: Выделить всё
userNotificationCenter(_:didReceive:withCompletionHandler:)Я использую:
- SwiftUI @ основное приложение
- @ UIApplicationDelegateAdaptor для AppDelegate
- Делегат UNUserNotificationCenter установлен вручную
- FirebaseAppDelegateProxy отключен
- Нет SceneDelegate
- Проверить параметры запуска?[.remoteNotification] (не запускается на iOS 15+)
- Добавление приложения (_:continue:restorationHandler:)
- Запретить появление баннеров во время запуска (предложение от ChatGPT, но никакой разницы)
У меня есть код:
Код: Выделить всё
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions:[UIApplication.LaunchOptionsKey : Any]?
) -> Bool {
UNUserNotificationCenter.current().delegate = self
return true
}
func userNotificationCenter(
_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void
) {
handleNotificationTap(response.notification.request.content.userInfo)
completionHandler()
}
public func handleNotificationTap(_ userInfo: [AnyHashable : Any]) {
let id = userInfo["notification_id"]
let notificationId = (id as? Int).map(String.init) ?? (id as? String)
if let finalId = notificationId {
Analytics.track("notification_opened", parameters: ["notification_id": finalId])
} else {
Analytics.track(
"notificationTappedWithoutID",
parameters: ["payload": userInfo]
)
}
}
Буду признателен за любую помощь. искал это уже несколько ночей.
Подробнее здесь: https://stackoverflow.com/questions/798 ... -is-killed
Мобильная версия