22
votes

I'm developing an app that uses Firebase push notifications. It worked well until I tried in iOS 11. Using an iphone with ios 11 the notifications don't arrive. Here's my code:

- (void)application:(UIApplication *)application 
  didReceiveRemoteNotification:(NSDictionary *)userInfo
  fetchCompletionHandler:(void (^)
  (UIBackgroundFetchResult))completionHandler {
      //Manage notification
  }

- (void)userNotificationCenter:(UNUserNotificationCenter *)center
   willPresentNotification:(UNNotification *)notification
     withCompletionHandler:(void (^)(UNNotificationPresentationOptions))completionHandler{
    //Manage notification
}

Neither of the methods are called.

Thanks for the help!

6
I'm having an issue on iOS 11 as well. I don't have an iOS 10 device to test on to confirm it is an OS issue but push was working now it isn't. I could receive notifications when calling the APNs server directly so there may be a firebase bug. I've reached out to support and let you know if I hear back.Jeremiah
Yeah it's probably caused by Firebase, maybe they will update soon.. Thanks for the answer @JeremiahJaime Alcántara Arnela

6 Answers

13
votes

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

1
votes

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
}
1
votes

Check this in your project capability. It's helped me) enter image description here

1
votes

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)
0
votes

Can you try this

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

I also faced with this issue. I followed all instructions bu still can not get the notifications in background.

When I archive and send build to test flight (and approved by apple) the problem is gone away. No I can send notifications.