Skip to content

Commit c39be85

Browse files
authored
Merge pull request #2149 from appwrite/doc-flutter-fcm
Add Flutter setup instructions for FCM in documentation
2 parents 822979a + 454763c commit c39be85

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,32 @@ 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:flutter/widgets.dart';
86+
import 'package:firebase_core/firebase_core.dart';
87+
import 'firebase_options.dart';
88+
89+
void main() async {
90+
WidgetsFlutterBinding.ensureInitialized();
91+
await Firebase.initializeApp(
92+
options: DefaultFirebaseOptions.currentPlatform,
93+
);
94+
runApp(MyApp());
95+
}
96+
```
97+
1. **For iOS**:
98+
- 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)
99+
- Upload your APNs authentication key to Firebase console under **Cloud Messaging** settings
100+
- Request notification permission at runtime using `FirebaseMessaging.instance.requestPermission()`
101+
1. **For Android**: FCM requires devices running Android 5.0 or higher with Google Play services installed.
102+
1. **For Web**: Add a `firebase-messaging-sw.js` file in your `web/` directory that imports the Firebase messaging SDK and handles background messages.
103+
{% /tabsitem %}
78104
{% /tabs %}
79105

80106
{% /section %}

0 commit comments

Comments
 (0)