fcm_notifications

Last updated:

0 purchases

fcm_notifications Image
fcm_notifications Images
Add to Cart

Description:

fcm notifications

Getting Started
In this section, you going to configue your Android and iOS project to use all features available in fcm_notifications:
Plugin Dependencies
Add the plugins bellow as a dependency in your pubspec.yaml file:
firebase_core: any
awesome_notifications: any
fcm_notifications: any
Android Configuration
1 - You MUST apply Google Play Services in your project to use FCM services. To do that, first you need to import com.google.gms:google-services package into your Android project, adding the line bellow in your build.gralde file, located at "android" folder. (Certifies to use the latest version)
buildscript {
...
dependencies {
...
classpath 'com.google.gms:google-services:4.3.10'
...
}
...
}
2 - Them, you need to apply google play services, adding the line bellow at the end of build.gralde file, located at "android/app" folder.
apply plugin: 'com.google.gms.google-services'
Now, your Android project is configured to use fcm_notifications
iOS Configuration
1 - First, ensure to have the last XCode version available instaled with at least Swift 5.5.7 (XCode version 14.A400).
2 - Run the command pod install inside your iOS project folder.
3 - To be able to add pictures and buttons on iOS push notifications, its necessary to create a Notification target extension using XCode. Target extensions are a type of lightweight application capable to run on background for specific tasks.
To do that, you need to open your Flutter project using XCode. Go to your iOS project folder and open the file Runner.xcfworkspace.
With your project opened, go to "File -> New -> Target" and chose "Notification Service Extension", next, add a name to your target extension, ending with "ServiceExtension".
4 - Now, you need to include Flutter and Fcm Notifications libraries to your Notification Service Extension. To do that you need to modify your "PodFile", adding the lines bellow at the end of the file, replacing the 2 mentions of MyAppServiceExtension by your service extension name:
################ FCM Notifications pod mod ###################
fcm_notifications_pod_file = File.expand_path(File.join('plugins', 'fcm_notifications', 'ios', 'Scripts', 'FcmNotificationPodFile'), '.symlinks')
require fcm_notifications_pod_file
target 'MyAppServiceExtension' do
use_frameworks!
use_modular_headers!
install_fcm_notifications_ios_pod_target File.dirname(File.realpath(FILE))
end
update_fcm_notifications_service_target('MyAppServiceExtension', File.dirname(File.realpath(FILE)), flutter_root)
################ FCM Notifications pod mod ###################
Them execute the command pod install to update your target extension.
5 - At this point, your target extension is able to use fcm notifications library. Inside your Target extension folder, edit the file NotificationService.swift, replacing the class UNNotificationServiceExtension by DartFcmServiceExtension and erasing all Notification Service content. The final file should look like this:
import UserNotifications
import fcm_notifications
@available(iOS 10.0, *)
class NotificationService: DartFcmServiceExtension {
}
6 - Also to build the app correctly, you need to ensure to set some build settings options for each of your app targets. In your project view, click on Runner -> Target Runner -> Build settings...
In Runner Target:
Build libraries for distribution => NO
Only safe API extensions => NO
iOS Deployment Target => 11 or greater
In your NotificationServiceExtension Target:
Build libraries for distribution => NO
Only safe API extensions => YES
iOS Deployment Target => 11 or greater
7 - Lastly, you need to add 3 capabilities to your XCode projec, specially "App Groups", allowing your target extensions to share data with each other.
To do this, run your application and search on debug console for the application group name automatically generated by Fcm Notifications. This name is unique for each application.
Them, open your XCode project, go to Targets -> Runner -> Singing and Capabilities -> Click on "+" icon and add "App Groups", "Push Notifications" and "Remote", checking "background fetching" and "remote notification" options.
On "App Groups", you need to add the app group name automatically generated by fcm notifications. This app group name MUST start with "group.". Them add the same "App Group" capability with the same app group name on your notification target extension.
Now, your iOS project is configured to use fcm_notifications.
Important notes
Push notifications on iOS DO NOT support IDs/Identifiers.
Push notifications are only delivered to real devices, all other features can be tested using simulators.
Push notifications are always delivered, even in a catastrophic error in your configuration, json package or notification service extension. In these cases, your notification is displayed as simply as possible. To allow you to avoid such situation, fcm sets these notifications with category "INVALID", and you can filter this category editing your info.plist, but you need to ask Apple for permission to do it. To know more about, please check com.apple.developer.usernotifications.filtering.
If you do not set "mutable_content" to true, your notification will not be delivered to NSE (Notification Service Extension) and modified to have fcm notification customizations. Instead, it will be delivered only with originals title and body content.
If you do not set "content_available" to true, your silent push notification will not be delivered.
Is recommended to set the badge value in the notification section at same time as in data, because in NSE failures, iOS will reade the badge value present in notification section. Meantime, Android FCM library does not delivery badge value inside notification section, so you need to set it inside data section.
You must not use silent push notifications to often, otherwise Apple will starts to block your device to run on background. You can use "Console.app" on MacOS to get the device's logs and check if your app is getting blocked.
Your push notifications can be denied on iOS if your users don't open your app for a long time. This limitation is canceled as soon as your user reopen your application manually.
To send push notifications in fcm notifications with all features available, you must use the standard below (Android and iOS sections are optional):
{
"to" : "{{fcm_token_ios}}",
"priority": "high",
"mutable_content": true,
"notification": {
"badge": 42,
"title": "Huston! The eagle has landed!",
"body": "A small step for a man, but a giant leap to Flutter's community!"
},
"data" : {
"content": {
"id": 1,
"badge": 42,
"channelKey": "alerts",
"displayOnForeground": true,
"notificationLayout": "BigPicture",
"largeIcon": "https://br.web.img3.acsta.net/pictures/19/06/18/17/09/0834720.jpg",
"bigPicture": "https://www.dw.com/image/49519617_303.jpg",
"showWhen": true,
"autoDismissible": true,
"privacy": "Private",
"payload": {
"secret": "Fcm Notifications Rocks!"
}
},
"actionButtons": [
{
"key": "REDIRECT",
"label": "Redirect",
"autoDismissible": true
},
{
"key": "DISMISS",
"label": "Dismiss",
"actionType": "DismissAction",
"isDangerousOption": true,
"autoDismissible": true
}
],
"Android": {
"content": {
"title": "Android! The eagle has landed!",
"payload": {
"android": "android custom content!"
}
}
},
"iOS": {
"content": {
"title": "Jobs! The eagle has landed!",
"payload": {
"ios": "ios custom content!"
}
},
"actionButtons": [
{
"key": "REDIRECT",
"label": "Redirect message",
"autoDismissible": true
},
{
"key": "DISMISS",
"label": "Dismiss message",
"actionType": "DismissAction",
"isDangerousOption": true,
"autoDismissible": true
}
]
}
}
}
To send silent push notifications, you must not use "notification" section and you need to use "content_available" instead of "mutable_content":
{
"to" : "{{fcm_token_ios}}",
"content_available": true,
"priority": "high",
"data" : {
"data1": "fb787aa2-6387-4f65-a5a2-125f96ab4c14",
"data2": "call_voice",
"data3": "3c3079b7-ab5e-48a5-8c61-b64ebb4910a9",
"data4": "5469846578",
}
}

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.