Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase notifications not working in iOS 11

Tags:

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!

like image 951
Jaime Alcántara Arnela Avatar asked Sep 21 '17 13:09

Jaime Alcántara Arnela


People also ask

Does Firebase notification work on iOS?

For Apple client apps, you can receive notification and data payloads up to 4000 bytes over the Firebase Cloud Messaging APNs interface.

Can FCM send notification to iOS?

Once your client app is installed on a device, it can receive messages through the FCM APNs interface. You can immediately start sending notifications to user segments with the Notifications composer, or messages built on your application server.

How do I get Firebase to push notifications?

Go to Firebase console — →Project Settings — →Cloud Messaging. To send the message select Body — →Raw — →JSON(application/json). You can send Notification Payload , Data Payload and even both using POSTMAN service.


2 Answers

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

like image 142
Jeremiah Avatar answered Sep 17 '22 18:09

Jeremiah


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 } 
like image 37
Adnan Aftab Avatar answered Sep 17 '22 18:09

Adnan Aftab