Reputation: 4841
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.
Upvotes: 1
Views: 2793
Reputation: 166
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:
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.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
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.
onMessage
callbackonResume
callbackonLaunch
callbackHowever, 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).
Upvotes: 3
Reputation: 4841
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.
pubspec.yaml
flutter packages get
Use the important pieces of the snippet below
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();
Upvotes: 5