backgroundNotificationListener function
NotificationCallback
backgroundNotificationListener(
- StreamSink backgroundNotificationStream,
- StreamSink notificationStream
Implementation
NotificationCallback backgroundNotificationListener(
StreamSink backgroundNotificationStream, StreamSink notificationStream) {
return (Map<String, dynamic> data) {
// Print notification payload data
print('Received notification: $data');
// Notification title
String notificationTitle = 'MyApp';
// Attempt to extract the "message" property from the payload: {"message":"Hello World!"}
String notificationText = data['message'] ?? 'Hello World!';
// Android: Displays a system notification
// iOS: Displays an alert dialog
Pushy.notify(notificationTitle, notificationText, data);
ENotificationMessage message = ENotificationMessage.fromJson(data);
backgroundNotificationStream.add(message);
notificationStream.add(message);
// Clear iOS app badge number
Pushy.clearBadge();
};
}