Getting started (Android)
Add app in your firebase console. You can follow this guide Firebase Setup. Just download google-services.json.
Copy google-services.json into your root of app assets directory this is important step.
Now in order to enable Firebase services in our Android app, add the google-services plugin to our Gradle files.
First in our root-level (project-level) Gradle file (android/build.gradle), add rules to include the Google Services Gradle plugin.
Check if the following configurations are available or not:
buildscript {
ext.kotlin_version = '1.8.0'
repositories {
google()
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.3.8'
}
}
allprojects {
repositories {
google()
mavenCentral()
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Now in our module (app-level) Gradle file (android/app/build.gradle), apply the Google Services Gradle plugin. For that, add the piece of code highlighted in the following code snippet to the ./android/app/build.gradle file of our project:
dependencies {
implementation platform('com.google.firebase:firebase-bom:29.0.0')
implementation 'com.google.firebase:firebase-messaging'
implementation 'com.android.support:multidex:2.0.1
}
apply plugin: 'com.google.gms.google-services'
Now, run the following command so that some automatic configurations can be made:
flutter pub get
Using Feedify you can also send http/ https URLs into the notifications hence to support them android has now introduced to add query parameters into your AndroidManifest.xml like below:
<queries>
<!-- If your app opens https URLs -->
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="https" />
</intent>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" />
</intent>
</queries>
You can read more at android developer site
Usage (common for Android and iOS)
void main() async {
initFeedSDK();
runApp(const MyApp());
}
void initFeedSDK() async {
WidgetsFlutterBinding.ensureInitialized();
var sdk = FeedSDK.getInstance(
feedifyKey: 'key',
feedifyDomain: 'domain',
feedifyUser: 'userKey');
// make sure notification icon is available for all screen sizes or else notification will fail to show!
FeedSDK.setNotificationIcon('resource://drawable/ic_notification');
Logs.setEnabled(true);
await sdk.init(
appName: 'your app name',
projectId: 'firebase project Id',
firebaseCurrentApiKey: 'firebase api key',
firebaseMobileSdkAppId: 'firebase mobile app sdk id',
firebaseStorageBucket: 'firebase storage key url',
firebaseUrl: '',
firebaseProjectNumber: 'firebase project number');
notificationDataCallback: (p0) {
Logs.d("data notification $p0");
},
);
}
- Note: All the above information can be found in google-services.json and info.plist file that has been already downloaded from Google firebase console.
If "notificationDataCallback" is passed then all the data will be sent back to the main calling app and the SDK's default behaviour will be overridden. You can read the data based on the keys available inside Constants class.
How to read the notification data in your app?
When FeedSDK.startScreen = '#any text' is set, then the data is passed to the root widget of your app, then you can read the data as below, which can be used for deeplinking or navigating through your app based on the notification data:
void initFeedSDK() async {
WidgetsFlutterBinding.ensureInitialized();
var sdk = FeedSDK.getInstance(
feedifyKey: 'key',
feedifyDomain: 'domain',
feedifyUser: 'userKey');
// make sure notification icon is available for all screen sizes or else notification will fail to show!
FeedSDK.setNotificationIcon('resource://drawable/ic_notification');
Logs.setEnabled(true);
await sdk.init(
appName: 'your app name',
projectId: 'firebase project Id',
firebaseCurrentApiKey: 'firebase api key',
firebaseMobileSdkAppId: 'firebase mobile app sdk id',
firebaseStorageBucket: 'firebase storage key url',
firebaseUrl: '',
firebaseProjectNumber: 'firebase project number');
notificationDataCallback: (p0) {
var icon = p0[Constants.icon];
var title = p0[Constants.title];
var body = p0[Constants.body];
var type = p0[Constants.type];
// and so on...
},
);
}
Getting started (iOS)
Integrating the Cloud Messaging plugin on iOS & macOS devices requires additional setup before your devices receive messages. There are also a number of prerequisites which are required to be able to enable messaging:
- You must have an active Apple Developer Account .
- For iOS; you must have a physical iOS device to receive messages.
- Firebase Cloud Messaging integrates with the Apple Push Notification service (APNs), however APNs only works with real devices.
For configuring FCM on iOS devices, follow the steps mentioned here and here.
The most important part in order to make this library work is here.