# Push Notification using FCM in Flutter(iOS)

**URL:** https://community.sendbird.com/t/push-notification-using-fcm-in-flutter-ios/3335
**Category:** Flutter
**Tags:** push-notification
**Created:** [November 6, 2021, 4:34pm UTC](https://community.sendbird.com/t/push-notification-using-fcm-in-flutter-ios/3335 "2021-11-06T16:34:21Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Arslan](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/arslan/32/1729_2.png) [@Arslan](https://community.sendbird.com/u/Arslan)
#### Post date: [November 6, 2021, 4:34pm UTC](https://community.sendbird.com/t/push-notification-using-fcm-in-flutter-ios/3335/1 "2021-11-06T16:34:21Z")

</div>

Hello,  
I am trying to send Push Notification to our Flutter App using FCM. While it is working fine with Android, it does not work with iOS. I believe the problem is that Sendbird does not send “content\_available” parameter in the notification payload. Due to this the onBackgroundMessage callback does not run, which in turn does not show the notification in the App. Please be informed that I am using flutter\_local\_notifications along with firebase\_messaging plugins.  
I want to know if someone else is also facing the same problem. Also, let me know if there is a better way to implement this feature.  
Thank You.

---

<div class="post-metadata">

### Author: ![sardorbek.numonov](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/sardorbek.numonov/32/697_2.png) [@sardorbek.numonov](https://community.sendbird.com/u/sardorbek.numonov)
#### Post date: [November 12, 2021, 4:34am UTC](https://community.sendbird.com/t/push-notification-using-fcm-in-flutter-ios/3335/2 "2021-11-12T04:34:30Z")

</div>

Hey @Arslan, Could you please send your app ID to me via DM (Direct Message)?

---

<div class="post-metadata">

### Author: ![Nicholas\_Latham](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/nicholas_latham/32/369_2.png) [@Nicholas\_Latham](https://community.sendbird.com/u/Nicholas_Latham)
#### Post date: [December 1, 2021, 8:21am UTC](https://community.sendbird.com/t/push-notification-using-fcm-in-flutter-ios/3335/3 "2021-12-01T08:21:08Z")

</div>

I am facing the same problem. I can get it to work with flutter\_apns, but would rather use firebase\_messaging as the flutter\_apns package is not updated. Did you manage to resolve this? Would be great if you could share your tips

---

<div class="post-metadata">

### Author: ![Woo](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/woo/32/125_2.png) [@Woo](https://community.sendbird.com/u/Woo)
#### Post date: [December 2, 2021, 2:24am UTC](https://community.sendbird.com/t/push-notification-using-fcm-in-flutter-ios/3335/4 "2021-12-02T02:24:18Z")

</div>

Hello @Arslan you need to upload apple certificate on sendbird dashboard and use APNS token to register in order to make push notification works on iOS device.

---

<div class="post-metadata">

### Author: ![Woo](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/woo/32/125_2.png) [@Woo](https://community.sendbird.com/u/Woo)
#### Post date: [December 2, 2021, 2:25am UTC](https://community.sendbird.com/t/push-notification-using-fcm-in-flutter-ios/3335/5 "2021-12-02T02:25:17Z")

</div>

> [@Nicholas\_Latham](#):
>
> I can get it to work with flutter\_apns, but would rather use firebase\_messaging as the flutter\_apns package is not updated. Did you

I think latest firebase messaging supports a feature for APNS token. You are no longer need to use flutter\_apns to register APNS token

---

<div class="post-metadata">

### Author: ![HelloHuddle](https://avatars.discourse-cdn.com/v4/letter/h/f475e1/32.png) [@HelloHuddle](https://community.sendbird.com/u/HelloHuddle)
#### Post date: [July 29, 2022, 6:49pm UTC](https://community.sendbird.com/t/push-notification-using-fcm-in-flutter-ios/3335/6 "2022-07-29T18:49:21Z")

</div>

We are also having issues with push notifications to Flutter+iOS in the same way that @Arslan describes. [This issue on github](https://github.com/firebase/flutterfire/issues/4300) goes into this, and [one commenter suggests patching the library](https://github.com/firebase/flutterfire/issues/4300#issuecomment-916883580) by removing two checks for gcm.message\_id. @Arslan, did you ultimately solve the issue, and if so, was it by patching the library in this way? @Woo, is there more insight you can provide on firebase messaging’s support for APNS tokens? Thank you, everyone!

---

<div class="post-metadata">

### Author: ![hotsunny.kang](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/hotsunny.kang/32/3135_2.png) [@hotsunny.kang](https://community.sendbird.com/u/hotsunny.kang)
#### Post date: [September 28, 2022, 5:25am UTC](https://community.sendbird.com/t/push-notification-using-fcm-in-flutter-ios/3335/7 "2022-09-28T05:25:48Z")

</div>

@Woo  
Having same issue for this.

Push notification does come in as APNs but I need the push to come as FCM not APNs.

so FCM’s onBackgroundMessage/onMessage.listen/onMessageOpenedApp.listen method’s cannot catch Sendbird’s push.

How do I have to solve this?

---

<div class="post-metadata">

### Author: ![rajveer](https://avatars.discourse-cdn.com/v4/letter/r/8edcca/32.png) [@rajveer](https://community.sendbird.com/u/rajveer)
#### Post date: [March 20, 2023, 3:37pm UTC](https://community.sendbird.com/t/push-notification-using-fcm-in-flutter-ios/3335/8 "2023-03-20T15:37:10Z")

</div>

Hello guys, we are facing same problem. IS there any solution available from Sendbird side or not?

---

<div class="post-metadata">

### Author: ![zvgandam](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/zvgandam/32/4590_2.png) [@zvgandam](https://community.sendbird.com/u/zvgandam)
#### Post date: [October 10, 2023, 9:32am UTC](https://community.sendbird.com/t/push-notification-using-fcm-in-flutter-ios/3335/10 "2023-10-10T09:32:55Z")

</div>

I have the same problem, did you solve it?

---

<div class="post-metadata">

### Author: ![asaarnak](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/asaarnak/32/2028_2.png) [@asaarnak](https://community.sendbird.com/u/asaarnak)
#### Post date: [October 10, 2023, 1:32pm UTC](https://community.sendbird.com/t/push-notification-using-fcm-in-flutter-ios/3335/11 "2023-10-10T13:32:24Z")

</div>

We disabled Sendbird Push Notifications feature and used Sendbird Webhooks feature and send the notifications from our own backend.

---

<div class="post-metadata">

### Author: ![GlennRuysschaert](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/glennruysschaert/32/5766_2.png) [@GlennRuysschaert](https://community.sendbird.com/u/GlennRuysschaert)
#### Post date: [February 25, 2025, 8:20am UTC](https://community.sendbird.com/t/push-notification-using-fcm-in-flutter-ios/3335/12 "2025-02-25T08:20:47Z")

</div>

Hello,  
We have the same issue.  
On iOS`FirebaseMessaging.onMessage` is not triggered.  
Because of this, we cannot push the app to open the chat screen route.  
This works on Android, but not iOS.

**EDIT:**  
Okay so I fixed it manually.  
What I did was update `AppDelegate.swift` to manually trigger the `onMessage` and `onMessageOpenedApp` events in Flutter.

This is my updated `AppDelegate.swift`:

```auto
import UIKit
import Flutter
import Firebase
import GoogleMaps
import flutter_local_notifications

@main
@objc class AppDelegate: FlutterAppDelegate {
    override func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        FirebaseApp.configure() // This must be done before GeneratedPluginRegistrant
        
        FlutterLocalNotificationsPlugin.setPluginRegistrantCallback { (registry) in
            GeneratedPluginRegistrant.register(with: registry)
        }
        
        GeneratedPluginRegistrant.register(with: self)
        
        if #available(iOS 10.0, *) {
            UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
        }
        
        // Handle notification tap when app was closed
        if let remoteNotification = launchOptions?[.remoteNotification] as? [AnyHashable: Any] {
            handleNotificationTap(remoteNotification)
        }
        
        return super.application(application, didFinishLaunchingWithOptions: launchOptions)
    }
    
    override func application(
        _ application: UIApplication,
        didReceiveRemoteNotification userInfo: [AnyHashable: Any],
        fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void
    ) {
        #if DEBUG
        print("APNs Push Notification Received: \(userInfo)")
        #endif
        
        if let controller = window?.rootViewController as? FlutterViewController {
            let channel = FlutterMethodChannel(
                name: "plugins.flutter.io/firebase_messaging",
                binaryMessenger: controller.binaryMessenger
            )
            
            let dictionary = convertToDictionary(userInfo)
            
            // If app is in foreground, show `onMessage`
            if application.applicationState == .active {
                channel.invokeMethod("Messaging#onMessage", arguments: dictionary)
            } else {
                // App is in background or inactive, handle with userNotificationCenter
            }
        }
        
        completionHandler(.newData)
    }
    
    // Detect when user taps notification in the foreground
    override func userNotificationCenter(
        _ center: UNUserNotificationCenter,
        didReceive response: UNNotificationResponse,
        withCompletionHandler completionHandler: @escaping () -> Void
    ) {
        let userInfo = response.notification.request.content.userInfo
        
        #if DEBUG
        print("Notification Tapped (Foreground): \(userInfo)")
        #endif
        
        handleNotificationTap(userInfo)
        completionHandler()
    }
    
    // Handle Notification Taps (Works for Background & Foreground)
    private func handleNotificationTap(_ userInfo: [AnyHashable: Any]) {
        let convertedData = convertToDictionary(userInfo)
        
        #if DEBUG
        print("Converted Notification Data (Before Sending to Flutter): \(convertedData)")
        #endif
        
        if let controller = window?.rootViewController as? FlutterViewController {
            let channel = FlutterMethodChannel(
                name: "plugins.flutter.io/firebase_messaging",
                binaryMessenger: controller.binaryMessenger
            )
            
            let finalPayload: [String: Any] = ["data": convertedData]
            channel.invokeMethod("Messaging#onMessageOpenedApp", arguments: finalPayload)
        }
    }
    
    // Convert userInfo (NSDictionary) to Flutter-readable dictionary
    private func convertToDictionary(_ userInfo: [AnyHashable: Any]) -> [String: Any] {
        var dictionary = [String: Any]()
        
        for (key, value) in userInfo {
            if let keyString = key as? String {
                dictionary[keyString] = unwrapValue(value)
            }
        }
        
        return dictionary
    }
    
    // Recursively unwrap nested dictionaries and arrays
    private func unwrapValue(_ value: Any) -> Any {
        if let dict = value as? [AnyHashable: Any] {
            return convertToDictionary(dict) // Recursively convert dictionary
        } else if let array = value as? [Any] {
            return array.map { unwrapValue($0) } // Recursively convert array
        } else {
            return value // Return primitive types as is
        }
    }
}

```
