Обеспечение доступности содержимого: 1 доступно в полезной нагрузке для фонового уведомления, а вот
// Push notification received
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("Error = ", error.localizedDescription)
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
let state = application.applicationState
DispatchQueue.main.async { // active
if state == .active {
PushManager.object().handlePushNotification(userInfo, isCameFromForeground: true)
} else if state == .background {
PushManager.object().handlePushNotification(userInfo)
} else {
PushManager.object().handlePushNotification(userInfo)
}
}
completionHandler(.newData)
}
// Notification handling for iOS 10
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let data = notification.request.content.userInfo
let state = UIApplication.shared.applicationState
DispatchQueue.main.async { // active
if state == .active {
PushManager.object().handlePushNotification(data, isCameFromForeground: true)
} else if state == .background {
PushManager.object().handlePushNotification(data)
} else {
PushManager.object().handlePushNotification(data)
}
}
completionHandler([.alert, .badge, .sound])
}
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
let data = response.notification.request.content.userInfo
let state = UIApplication.shared.applicationState
DispatchQueue.main.async { // active
if state == .active {
PushManager.object().handlePushNotification(data, isCameFromForeground: true)
} else if state == .background {
PushManager.object().handlePushNotification(data)
} else {
PushManager.object().handlePushNotification(data)
}
}
completionHandler()
}