Я хочу добавить фоновую выборку для моего приложения, когда приходит тихое удаленное уведомление (с content-available: 1), поэтому, когда оно приходит, я запускаю фоновое обновление локально, проверяю новые данные и, если да, генерирую локальноеpush-уведомление для пользователя.Тем не менее, он прекрасно работает, только когда приложение находится в фоновом режиме, не приостановлено или не запущено.В этих состояниях я получаю его для получения некоторых данных, но локальное уведомление не запускается (оно создается, как видно на консоли устройства), есть идеи, как мне это решить?
Вот мой код для генерации push (работает как положено)
func generatePushNotification(with title: String, body: String, badge: Int = 1){
let content = UNMutableNotificationContent()
content.badge = badge as NSNumber
content.title = title
content.body = body
content.sound = UNNotificationSound.default
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1,
repeats: false)
let notification = UNNotificationRequest(identifier: "pushLocal", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(notification) { (error) in
if error != nil {
NSLog((error?.localizedDescription)!)
}
}
}
Вот мой код для извлечения уведомлений
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
networkManager.getScheduleForGroup(group) { (resp, error) in
self.generatePushNotification(with: "Back", body: "ground")
completionHandler(.newData)
}
completionHandler(.noData)
}
Вот вывод на консоль:
dasd CANCELED: com.apple.pushLaunch.**:297454 <private>!
SpringBoard Saving notification 802A-AE8C: 0 [ hasAlertContent: 0, shouldPresentAlert: 1 ]
SpringBoard Delivered user visible push notification 802A-AE8C
SpringBoard Load 0 pending notification dictionaries
SpringBoard Adding notification 802A-AE8C to destinations 0 [ hasAlertContent: 0, shouldPresentAlert: 1 hasSound: 0 shouldPlaySound: 1 ]