В моем проекте у меня есть как метод didReceiveRemoteNotification
, так и методы UNUserNotificationCenter didReceive
и willPresent
. В одном граничном случае я наблюдал пуш-уведомление, приходящее на устройство, но методы не вызывались. Я подозреваю, что крайний случай - прерывистое подключение к сети. Правильно ли мое предположение? Как мне поступить с этим?
Вот тело самого толчка:
{
"aps": {
"content-available": 1,
"alert": "...",
"badge": "1",
"sound": "mailsent.wav"
},
...
}
Вот метод didReceiveRemoteNotification
:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
if let type = ... {
switch type {
case "...":
self.handle(userinfo: userInfo, completion: { (value) -> (Void) in
if (value == true) {
completionHandler(.newData)
} else {
completionHandler(.failed)
}
})
break
default:
completionHandler(.newData)
break
}
} else {
completionHandler(.noData)
}
}
А вот методы didReceive
и willPresent
:
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Swift.Void) {
...
completionHandler()
}
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Swift.Void) {
...
completionHandler(.alert)
}