📜  flutter firebase_messaging 9 ios - Dart (1)

📅  最后修改于: 2023-12-03 15:30:48.307000             🧑  作者: Mango

Flutter Firebase Messaging on iOS - Dart

Introduction

Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you reliably deliver messages at no cost. Firebase Cloud Messaging on iOS allows developers to send push notifications to iOS devices. This guide will walk you through the process of adding Firebase Cloud Messaging to your Flutter iOS app using the Firebase Messaging plugin.

Prerequisites

Before you start, make sure you have the following installed on your development machine:

  • Flutter SDK
  • Xcode
  • An active Firebase project with Firebase Cloud Messaging enabled.
Adding Firebase Messaging to your app
  1. Open your terminal and navigate to your Flutter project directory.
  2. Add the Firebase Messaging plugin to your pubspec.yaml file:
dependencies:
  firebase_messaging: ^9.0.0
  1. Run flutter pub get to install the plugin.
  2. Follow the iOS setup guide to add Firebase to your iOS project.
  3. Configure your app to handle incoming notifications by setting up a FirebaseMessaging.onMessage stream in your main Dart file:
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
  // Handle the incoming message
});
Testing push notifications
  1. Build and run your app on a simulator or device.
  2. In the Firebase console, send a test notification to your app.
  3. If everything is configured correctly, you should receive the notification on your device.
Conclusion

Firebase Cloud Messaging is a great solution for sending push notifications to iOS devices. By following this guide, you should now have Firebase Cloud Messaging set up in your Flutter iOS app. Happy coding!