Push-уведомления iOS перестают работать после добавления Firebase SDK - PullRequest
0 голосов
/ 22 мая 2018

Я использую push-уведомления в своем проекте с APNS.Push-уведомления хорошо работали, прежде чем добавить и настроить Firebase SDK.Я заметил, что после добавления Firebase функция: didRegisterForRemoteNotificationsWithDeviceToken не вызывается.

Я не знаю, есть ли что-то, что мне нужно отключить в Firebase, если я удалю настройку Firebase (FirebaseApp.configure ()), функция didRegisterForRemoteNotificationsWithDeviceToken вызывается снова.

Мой код:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // ... existing code ...
    registerForPushNotifications()
    return true
}

func registerForPushNotifications() {
    UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) {
        (granted, error) in
        print("Permission granted: \(granted)")

        guard granted else { return }
    }
}

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    let tokenParts = deviceToken.map { data -> String in
        return String(format: "%02.2hhx", data)
    }

    let token = tokenParts.joined()
    print("Device Token: \(token)")
}

func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
    print("Failed to register: \(error)")
}

1 Ответ

0 голосов
/ 23 мая 2018

Просто отключите метод Swizzling в FCM: https://firebase.google.com/docs/cloud-messaging/ios/client#method_swizzling_in

...