Firebase notifications not working in iOS 11

霸气de小男生 提交于 2019-12-04 22:32:54

This is an issue with Firebase. It seems to be related to a recent update of theirs instead of iOS 11. They are working on a fix for it.

In the meantime if you add pod 'FirebaseInstanceID', '2.0.0' to your podfile it will fix it.

You can read more here: https://github.com/firebase/quickstart-ios/issues/327#issuecomment-332655731

You need to implement UNUserNotificationCenterDelegate

 extension AppDelegate: UNUserNotificationCenterDelegate {
        func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
            completionHandler(.alert)
        }
    }

and set it to UNUserNotificationCenter object inside didFinishLaunchingWithOptions

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
      UNUserNotificationCenter.current().delegate = self
      return true
}

Check this in your project capability. It's helped me)

Can you try this

    Messaging.messaging().delegate = self
    Messaging.messaging().shouldEstablishDirectChannel = true

I got stuck like 3 hours and then 2 steps found on net helped me.

  1. Try call firebase notification send externally like this - just replace ServerKey for your account serverkey and FCM_TOKEN for your app fcm token:
curl -X "POST" "https://fcm.googleapis.com/fcm/send" \
     -H "Authorization: key=ServerKey" \
     -H "Content-Type: application/json" \
     -d $'{
  "notification": {
    "body": "Testing with direct FCM API",
    "title": "Test Message",
    "badge": "0",
    "sound": "default"
  },
  "registration_ids": [
"FCM_TOKEN"
  ]
}'
  1. You will get some error response probably. I've got "InvalidApnsCredential" which was due to not matching TeamID in firebase and apple developer account (more specifically auth token key) -> also be careful that firebase really changes TeamID event after save (it gave me many invalid save changes which occured after browser refresh)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!