Фоновое уведомление Firebase в Swift не работает - PullRequest
0 голосов
/ 25 сентября 2019

Я пытаюсь заставить фоновые уведомления работать в моем приложении, и оно не работает.он работает, когда приложение находится на переднем плане, и я могу получать уведомления о подписанных темах, но не тогда, когда приложение или телефон закрыты, а когда это только на одно устройство.У меня есть все возможности и т.д., и разрешения в настройках разрешены.Я, должно быть, что-то упускаю.

Вот что в моем текущем делегате приложения:

    func setupForNotifications() {
    Messaging.messaging().delegate = self
    Messaging.messaging().subscribe(toTopic: "global")
    UNUserNotificationCenter.current().delegate = self
}

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    Messaging.messaging().apnsToken = deviceToken
    // Instance ID Check
    InstanceID.instanceID().instanceID { (result, error) in
        if let error = error {
            print("Error fetching remote instance ID: \(error)")
        } else if let result = result {
            print("Firebase cloud messaging ID token: \(result.token)")
        }
    }
}

func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
    print("Unable to register for remote notifications: \(error.localizedDescription)")
}

func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
    print("Receiving message content")
    DataService.shared.processUpdateNotification(remoteMessage.appData)
}

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    print("Receiving content")
    Messaging.messaging().appDidReceiveMessage(userInfo)
    DataService.shared.processUpdateNotification(userInfo)
    completionHandler(UIBackgroundFetchResult.newData)
}

func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
    let dataDict:[String: String] = ["token": fcmToken]
    NotificationCenter.default.post(name: Notification.Name("FCMToken"), object: nil, userInfo: dataDict)
    UserService.shared.updateFCMToken(token: dataDict)
}

func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
    let userInfo = notification.request.content.userInfo
    DataService.shared.processUpdateNotification(userInfo)
}

Есть ли что-то, что я пропускаю - файл .p8 правильный, и входящее уведомление содержит оба содержимогодоступно и значение приоритета установлено.

Спасибо.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...