简体   繁体   中英

What are the requirements for FCM to work with Flutter on iOS?

I am working on getting Firebase Cloud Messaging to work with iOS via Flutter. I have followed the steps laid out here , here , and and here with no luck.

I am NOT using simulator, I am on an iPhone 8+ with iOS 11.4.1. I have installed all three APN certs in Firebase console. I have called FirebaseMessaging.requestNotificationPermissions(); and accepted the dialog. I am testing by sending messages through FCM console. I have my phone auth'd with Firebase (anonymous auth).

I do not receive messages with the app open or closed.

If anyone has any thoughts on what I might be missing, please assist. I would like to be able to make a bulletpoint list for others coming to Flutter/iOS/FCM to just follow without errors.

Sounds like you are missing some configuration steps in order to be able to send push notifications to your iOS App. Maybe the best that you can do is post more information about your configuration environment.

However, for the description that you give us, it can be an issue about one of the following options:

  • You need to configure the correct environment to send the push notification. If you install the app to the device directly from Xcode you need to use the Sandbox environment, but if your app is installed from AppStore or Testflight, you need to use Production . This is because both environment (sandbox and production) refers to different urls to send the push notification.
  • The deviceId related to the specific relation between your app and the current device is not stored. Remember, when you send a push notification you need to give which devices will receive that notification.

Please let me know if this responds your question or there is some that I've missing

EDIT

To handle foreground notifications you need to add the didReceiveRemoteNotification callback in order to get the title , message all the custom parameters of the JSON structure.

In this particular case, the plugin documentation says that you need three different callbacks, depending on the application status.

  • If the app is in FOREGROUND you need to use onMessage callback
  • If the app is in BACKGROUND you need to use onResume callback
  • If the app is TERMINATED you need to use onLaunch callback

However, this only make the parameters info available, you still needs to show them to the user in some custom way (for example WhatsApp or Facebook Messenger can show you the new chat message if you are in a different conversation as a independent bubble on top of the view, or this new message is added to the bottom of the conversation if it belongs to the current chat).

Alright, this is what I learned. Wish I had written this all down right when I got it working. But it should be helpful to someone.

  1. Make sure Firebase is setup and working in your Flutter project.
  2. Add firebase_messaging to pubspec.yaml
  3. flutter packages get
  4. Create/download your APNS key and upload it to Firebase console
  5. Create/download your Provisioning Profile on Apple Dev website and double-click to install.
  6. Use the important pieces of the snippet below

  7. Send a message to all app users, or your messagingToken through Firebase console.

If you have a physical device running your app and you follow these steps, you should receive background notifications. You will not receive them in the foreground. If someone figures out how to get them in the foreground, let me know!

snippet

import 'package:firebase_messaging/firebase_messaging.dart';

FirebaseMessaging messaging = FirebaseMessaging();

messaging.configure(); // NECESSARY
messagingToken = await fb.messaging.getToken();
messaging.subscribeToTopic("general");

// this will launch a modal asking if you want to receive notifications
messaging.requestNotificationPermissions();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM