notification_reactor 0.0.3+1 notification_reactor: ^0.0.3+1 copied to clipboard
For DIY engineers! Define your own reaction by Push Notification (via APNs (iOS) / FirebaseCloudMessaging (Android)).
notification_reactor #
For DIY engineers! Define your own reaction by Push Notification (via APNs (iOS) / FirebaseCloudMessaging (Android)).
Getting Started #
Android Integration #
To integrate your plugin into the Android part of your app, setup Firebase:
- Using the Firebase Console add an Android app to your project:
Follow the assistant, download the generated
google-services.json
file and place it insideandroid/app
. - Modify the
android/build.gradle
file and theandroid/app/build.gradle
file to add the Google services plugin as described by the Firebase assistant. - Implement your original
FirebaseMessagingService
in Java/Kotlin. Recommending to create yourNotificationCompat
usingsupport-compat
. When you makeNotification
withPendingIntent
, you should containsRemoteMessage
object you received with key"EXTRA_PUSH_MESSAGE"
.
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Intent launchApp = new Intent();
launchApp.putExtra("EXTRA_PUSH_MESSAGE", remoteMessage);
launchApp.setClass(this, MainActivity.class);
PendingIntent onTapNotification = PendingIntent.getActivity(this, 0, launchApp, PendingIntent.FLAG_ONE_SHOT);
...
NotificationBuilder builder = (new NotificationCompat.Builder(...))
.setContentIntent(onTapNotification);
...
}
(Please see this tutorial if you want.)
iOS Integration #
To integrate your plugin into the iOS part of your app, follow these steps:
- Generate the certificates from Apple developer center for receiving push notifications. (Please see this article if you want the tutorial.)
- Enable
Push Notification
inCapabilities
tab in Xcode opening yourios/Runner.xcworkspace
.
Dart/Flutter Integration #
From your Dart code, you need to import the plugin and instantiate it:
import 'package:notification_reactor/notification_reactor.dart';
final reactor = NotificationReactor();
To set handler for Push Notifications, call setHandlers()
:
reactor.setHandlers(
onLaunch: (Map<String, dynamic> message) { /* Called when your app launched by PushNotifications */ },
onResume: (Map<String, dynamic> message) { /* Called when your app become foreground from background by PushNotifications */ },
onMessage: (Map<String, dynamic> message) { /* Called when receive PushNotifications during your app is on foreground */ },
);
... and send pushes from your server!
When you send pushes, you need APNs/FCM push token. To get token, recommending to use plain_notification_token.