Get immediate access to this and 4,000+ other videos and books.

Take your career further with a raywenderlich.com Pro subscription. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it’s simply the best investment you can make in your development career.

Add Cloud Messaging to Your App Pro

This video was last updated on Aug 30 2022

When receiving notifications your app may be in the foreground, background or terminated. Learn how to react to notifications in each of these states.

Contributors

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

You can unlock the rest of this video course, and our entire catalogue of books and videos, with a raywenderlich.com Professional subscription.

The Flutterfire plugin that adds the Cloud Messaging capabilities is called firebase_messaging.

flutter pub add firebase_messaging 
import 'package:firebase_messaging/firebase_messaging.dart'; 
final messaging = FirebaseMessaging.instance; 
FirebaseMessaging.onBackgroundMessage(_handleMessage); 
Future<void> _handleMessage(RemoteMessage message) async { 
  print('background message title ${message.notification!.title}'); 
  print('background message body ${message.notification!.body}'); 
  print('background data ${message.data.length}'); 
} 
FirebaseMessaging.onMessage.listen((RemoteMessage message) { 
    print('Message received in the foreground!'); 
    if (message.notification != null) { 
      print( 
          'Message notification: ${message.notification?.body}'); 
    } 
  }); 

Reviews

Comments