Usage
Once after the setup, import the namespace to access the features from Notification Services.
Request Access (for presentation options)
A notification can have a visual display, sound, badge and other properties. You need to request them based on how you want to present the notifications to the user with RequestPermission method.
Check for other permission options in NotificationPermissionOptions available on iOS specifically.
Get Settings
You can check what settings user allowed with GetSettings method. This will be handy if you want to check if user denied the settings so that you can prompt him with suitable message.
If you see user didn't allow the permission earlier, you can use Utilities. OpenApplicationSettings method to let user to enable the permission for using the notifications display feature.
Local Notifications
Create a Notification Message
For scheduling notifications, you need to create an instance of INotification.
Schedule Notification
For scheduling a notification, you need to have an instance of INotification which contains the details required for a notification. Use ScheduleNotification for scheduling the notification.
The above call will schedule the notification instantly and incase if you want to schedule in the future, you need to set the Time Interval Trigger
Repeat Notifications
When setting the time interval notification you can pass additionally repeat status to repeat the notification. The below notification repeats every 10 seconds.
Get Scheduled Notifications
You can get the list of all scheduled notifications and not yet delivered with GetScheduledNotifications
Cancel Scheduled Notification/Notifications
As each notification has an unique Id (assigned when creating), you can cancel the notification with this id.
Cancel all scheduled notifications
Get Delivered Notifications
GetDeliveredNotifications return all the notifications delivered in the Android or iOS notification center.
Remove Delivered Notifications
RemoveAllDeliveredNotifications removes all notifications delivered in the Android or iOS notification center .
Push Notifications or Remote Notifications
While local notifications are created locally and delivered to the device, Push notifications needs an external/backend server to deliver the notification to device.
Go through the following steps to understand how a push notification works.
Device registers for push notifications and receive a token
The token(also known as device token or registration token) will be sent to your backend server
Your backend server constructs the message payload it wants to pass to your device and sends a request to the platform's notification servers (APNS on iOS and FCM on Android) along with the device token it received in step 2.
Platform's notification servers then targets the device with the device token and pushes the message payload to the device.
Yay! 👯♂️ Your device will receive a notification!
Remote Notifications Management
For getting the device token, you first need to register for push notifications. In the callback, you get the device token.
Once after registration, the plugin caches the device token for your future usability. You can fetch with NotificationServices.CachedSettings.DeviceToken
Also, you can check if remote notifications are already registered on the device with IsRegisteredForRemoteNotifications
Once you are done with the remote notifications, you can unregister for the push notifications.
If your user disables the push notifications, unregistering for remote notifications will save battery on the device!
Detecting App launch through Notification
There will be cases where you need to identify if the app is launched when user clicked on the notification from Notification Center.
INotification has a property IsLaunchNotification property which tells if the notification is launched on user tap.
Plugin automatically delays delivering the notification until you register for NotificationServices.OnNotificationReceived event. Once you register, plugin delivers with IsLaunchNotification variable set to true if it's tapped by the user.
Last updated