Skip to content

Instantly share code, notes, and snippets.

@MahefaAbel
Created March 17, 2022 08:51
Show Gist options
  • Save MahefaAbel/01f60e1c04d28708a9ef5c92525a3362 to your computer and use it in GitHub Desktop.
Save MahefaAbel/01f60e1c04d28708a9ef5c92525a3362 to your computer and use it in GitHub Desktop.
Firebase Cloud Messaging for Flutter
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
_firebaseMessaging.configure(
onLaunch: (Map<String, dynamic> message) {
print('onLaunch called');
},
onResume: (Map<String, dynamic> message) {
print('onResume called');
},
onMessage: (Map<String, dynamic> message) {
print('onMessage called');
},
);
_firebaseMessaging.subscribeToTopic('all');
_firebaseMessaging.requestNotificationPermissions(IosNotificationSettings(
sound: true,
badge: true,
alert: true,
));
_firebaseMessaging.onIosSettingsRegistered
.listen((IosNotificationSettings settings) {
print('Hello');
});
_firebaseMessaging.getToken().then((token) {
print(token); // Print the Token in Console
});
}
@MahefaAbel
Copy link
Author

pubspec.yaml

dependencies:
  firebase_messaging: ^6.0.16

flutter packages get

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment