Skip to content

Commit 8a6104f

Browse files
committed
Add Flutter setup instructions for FCM in documentation
1 parent bb11ddc commit 8a6104f

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/routes/docs/products/messaging/fcm/+page.markdoc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,31 @@ Some additional configuration is required to enable push notifications in your m
7575
1. Add push notification capability to your app by clicking your root-level app in XCode > **Signing & Capabilities** > {% icon icon="plus" size="m" /%} Capabilities > Search for **Push Notifications**.
7676
1. If using SwiftUI, disable swizzling by setting `FirebaseAppDelegateProxyEnabled` to `NO` in your `Info.plist`.
7777
{% /tabsitem %}
78+
{% tabsitem #fcm-flutter title="Flutter with FCM" %}
79+
1. Install the [Firebase CLI](https://firebase.google.com/docs/cli) and [FlutterFire CLI](https://pub.dev/packages/flutterfire_cli).
80+
1. From your Flutter project directory, configure Firebase by running `flutterfire configure`.
81+
1. Add the Firebase messaging plugin to your Flutter project with `flutter pub add firebase_messaging`.
82+
1. Add the Firebase core plugin if not already added with `flutter pub add firebase_core`.
83+
1. Initialize Firebase in your `lib/main.dart` file:
84+
```dart
85+
import 'package:firebase_core/firebase_core.dart';
86+
import 'firebase_options.dart';
87+
88+
void main() async {
89+
WidgetsFlutterBinding.ensureInitialized();
90+
await Firebase.initializeApp(
91+
options: DefaultFirebaseOptions.currentPlatform,
92+
);
93+
runApp(MyApp());
94+
}
95+
```
96+
1. **For iOS**:
97+
- Enable push notifications and background modes in XCode by opening `ios/Runner.xcworkspace` and adding the **Push Notifications** capability and **Background Modes** (Background fetch and Remote notifications)
98+
- Upload your APNs authentication key to Firebase console under **Cloud Messaging** settings
99+
- Request notification permission at runtime using `FirebaseMessaging.instance.requestPermission()`
100+
1. **For Android**: FCM requires devices running Android 5.0 or higher with Google Play services installed.
101+
1. **For Web**: Add a `firebase-messaging-sw.js` file in your `web/` directory that imports the Firebase messaging SDK and handles background messages.
102+
{% /tabsitem %}
78103
{% /tabs %}
79104

80105
{% /section %}

0 commit comments

Comments
 (0)