Remote Push Notifications

This functionality and page is not yet complete.

Wisej.NET Hybrid Applications can use Apple Push Notification Service (APNS) for iOS and Firebase Cloud Messaging (FCM) for Android to send and process push notifications within a Hybrid project.

How Remote Push Notifications Work

  1. Registration for Notifications: When a user installs and opens a mobile or web application for the first time, the application requests to register for push notifications. This is often seen as a prompt asking the user if they want to allow notifications.

  2. Device Token or Identifier: Upon granting permission, the application receives a unique token or identifier from the push notification service of the device's operating system (like Apple Push Notification Service for iOS or Firebase Cloud Messaging for Android).

  3. Sending the Token to Server: The application sends this token to the application server. This token is used to identify the device and send messages to it.

  4. Server Sends a Notification Request: When the server decides to send a notification (which could be triggered by various events), it sends a request to the push notification service, including the message and the device token.

  5. Push Notification Service: The push notification service (like APNS for iOS or FCM for Android) receives the request and sends the notification to the correct device using the provided token.

  6. Receiving the Notification: The user's device receives the notification and displays it, even if the application is not currently open.

Setup

NuGet Packages

Add Wisej-3-Hybrid-PushNotifications to your Wisej.NET Hybrid Local Application or Wisej.NET Hybrid Remote Application project.

Add Wisej-3-Hybrid-PushNotifications-Native to your Wisej.NET Hybrid Client Application project.

Register Client Extension

After adding the required NuGet packages to the projects, register the push notifications extension in the Hybrid Client Application project startup file:

Registering for Push Notifications

To use push notifications on Android or iOS, you must request a remote notification token. Within a Wisej.NET Hybrid application this can be achieved using the following lines of code:

private void Page1_Load(object sender, EventArgs e)
{
	// get remote notification info.
	var info = Device.Info.Use<DeviceRemoteNotificationInfo>();
	
	// check for existing remote notification token.
	var token = info.RemoteToken;
	
	// if the user doesn't have a token,
	// attach to remote notification registration events.
	if (String.IsNullOrEmpty(token)
	{
		var notifications = Device.Use<DeviceRemoteNotification>();

		notifications.DidRegisterForRemoteNotifications += Notifications_DidRegisterForRemoteNotifications;
		notifications.DidFailToRegisterForRemoteNotifications += Notifications_DidFailToRegisterForRemoteNotifications;
	}	
}

private void Notifications_DidFailToRegisterForRemoteNotifications(object sender, string e)
{
	// registration for remote tokens failed, show an alertbox.
	AlertBox.Show(e, MessageBoxIcon.Error);
}

private void Notifications_DidRegisterForRemoteNotifications(object sender, string e)
{
	// registration for remote tokens succeeded, do something with result.
	this.textBox1.Text = e;
}

Processing Push Notifications

There are multiple scenarios where push notifications can be handled within the application.

Last updated