Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Push notification not working on iOS #5

Open
famedly-bot opened this issue Jun 8, 2023 · 2 comments
Open

Push notification not working on iOS #5

famedly-bot opened this issue Jun 8, 2023 · 2 comments

Comments

@famedly-bot
Copy link

In GitLab by @paulhuanggitlab on Jun 8, 2023, 08:28

Description

Recently, I have been working on enabling push notifications in FluffyChat.
It works fine on Android, but I'm facing issues with iOS. After investigating,

I found that in the Pods/FirebaseMessaging/FirebaseMessaging module, the appDidReceiveMessage method is receiving the notifications correctly. However, the data is not being sent to the method channel in FcmSharedIsolatePlugin.

Any steps I missing or can somebody explain how it work? Appreciate.

Service,Platform & Version

  • iOS 16.4
  • iPhone 14
@eslex01x
Copy link

any something new on this issue and ?? 👀

@vanyasem
Copy link

I don't think that iOS notifications are implemented at all judging by this line here:

channel.invokeMethod("token", arguments: [token])

It appears that on the iOS platform side, only FCM token updates are listened to, and transmitted to Flutter.

I don't think that this plugin has much use on iOS anyways
If you read the Firebase Messaging docs for Flutter, you'll learn that

When messages are received, an isolate is spawned (Android only, iOS/macOS does not require a separate isolate)

This plugin (as stated in the name), provides Firebase Messages in a shared isolate (as opposed to a separate isolate), thus allowing you to access application's context and state. iOS implementation of Firebase Messages already runs in a shared isolate, thus having no need for a separate plugin.

While cumbersome, you can support both Android and iOS with the following snippet:

if (Platform.isIOS) {
  FirebaseMessaging.onBackgroundMessage(
    (final RemoteMessage message) async {
      _handlePushMessage(message.data);
    },
  );
  FirebaseMessaging.onMessage.listen(
    (final RemoteMessage message) async {
      _handlePushMessage(message.data);
    },
  );
}
if (Platform.isAndroid) {
  final FcmSharedIsolate firebase = FcmSharedIsolate();
  firebase.setListeners(
    onMessage: (message) {
        final Map<dynamic, dynamic> messageData = message['data'] ?? message;
      _handlePushMessage(messageData);
    },
  );
}
Future<void> _handlePushMessage(Map<dynamic, dynamic> messageData) {
  // Handle the push
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants