update readme

This commit is contained in:
Salvatore Giordano
2020-04-16 16:35:12 +02:00
parent ed2124cf74
commit d1452f22d5
-129
View File
@@ -162,135 +162,6 @@ By default the library saves information about channels and messages in a SQLite
Set the property `persistenceEnabled` to false if you don't want to use the offline storage.
### Push notifications
To enable push notifications set the property `pushNotificationsEnabled` to `true`.
#### Android
Follow the guide at [this link](https://pub.dev/packages/firebase_messaging#android-integration) to setup Firebase for Android.
Set the notification template on your GetStream dashboard to be like this:
```json
template = {}
data template = {
"message_id": "{{ message.id }}"
}
```
Create a Application.kt file to be like this:
```kotlin
class Application : FlutterApplication(), PluginRegistrantCallback {
override fun onCreate() {
super.onCreate()
FlutterFirebaseMessagingService.setPluginRegistrant(this)
}
override fun registerWith(registry: PluginRegistry?) {
PathProviderPlugin.registerWith(registry?.registrarFor(
"io.flutter.plugins.pathprovider.PathProviderPlugin"))
SharedPreferencesPlugin.registerWith(registry?.registrarFor(
"io.flutter.plugins.sharedpreferences.SharedPreferencesPlugin"))
FlutterLocalNotificationsPlugin.registerWith(registry?.registrarFor(
"com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin"))
FirebaseMessagingPlugin.registerWith(registry?.registrarFor("io.flutter.plugins.firebasemessaging.FirebaseMessagingPlugin"))
}
}
```
Update the `AndroidManifest.xml` file to set the application class:
```xml
...
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:name=".Application"
android:label="example"
android:icon="@mipmap/ic_launcher">
<activity
android:name=".MainActivity"
android:launchMode="singleTop"
...
```
##### 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<void> _handleAndroidNotification(
Map<String, dynamic> 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 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`
- add `App Groups` capability to the `Runner` target and the just created one and create one common group
- add the line `pod 'StreamChatClient'` to the Podfile
- run `pod install`
- substitute the code in the `Notification service` with [this one](https://gist.github.com/imtoori/d37611faefef036e1a6c017b1a09e91f) and substitute APPGROUP with the just created one
- do the same with `AppDelegate.swift` using [this template](https://gist.github.com/imtoori/f95b30f25b745c5f777bfff1085176ef)
- set the notification template on your GetStream dashboard to be like this:
```handlebars
template = {
"aps" : {
"alert" : {
"title" : "{{ sender.name }} @ {{ channel.name }}",
"body" : "{{ message.text }}"
},
"badge": {{ unread_count }},
"apns-priority": 10,
"mutable-content" : 1
},
"message_id": "{{ message.id }}"
}
```
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,