From b7ad70f6cd310af8b8e61058c054989d977bb376 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Tue, 14 Apr 2020 15:24:08 +0200 Subject: [PATCH] Update README.md --- README.md | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9b495747..47894c46 100644 --- a/README.md +++ b/README.md @@ -213,11 +213,55 @@ Update the `AndroidManifest.xml` file to set the application class: ... ``` +##### Customizing notifications + +To customize notifications pass a function as the named parameter `androidNotificationHandler` to the `Client` constructor. + +It has to be a top-level function or a static method. + +The class `NotificationService` provides some helper methods to use to handle the notification. + +You can start from this template to write the `androidNotificationHandler` function: + +```dart +Future _handleAndroidNotification( + Map notification, +) async { + // get message information from the backend and store it in the offline storage + final notificationData = await NotificationService.getAndStoreMessage(notification); + + // define the android channel specifics + final androidPlatformChannelSpecifics = AndroidNotificationDetails( + 'Message notifications', + 'Message notifications', + 'Channel dedicated to message notifications', + importance: Importance.Max, + priority: Priority.High, + ); + + // define the appearance of the notification + final androidNotificationOptions = AndroidNotificationOptions( + androidNotificationDetails: androidPlatformChannelSpecifics, + id: notificationData.message.id.hashCode, + title: + 'CUSTOM ${notificationData.message.user.name} @ ${notificationData.channel.cid}', + body: notificationData.message.text, + ); + + // actually show the notification + await NotificationService.showNotification(androidNotificationOptions); +} +``` + #### iOS Make sure you have correctly configured your app to support push notifications, and that you have generated certificate/token for sending pushes. -##### Offline support for push notifications +##### Offline support and customizing notifications + +On iOS we need to create a notification service extension. + +Follow these points to configure it - open the XCode project - create a new target of type `Notification service extension` @@ -243,6 +287,10 @@ template = { ``` Of course you can change the `alert` object as you want. Just make sure it has the last three lines. +To customize notifications on iOS you need to do it in the Notification service. + +There is no way of doing it using Dart code at the moment because of framework restrictions. + ## Contributing We welcome code changes that improve this library or fix a problem,