Before you can send push notifications to a device that is running your app, you need to initialize and register it.
- Initialization contacts the Microsoft Push Notification Service (MPNS) and enables your app to receive push notifications. This step includes acquiring a push token that authorizes Telerik Platform to send messages to the device.
- Registration sets up Telerik Platform to send push notification to the device. This step includes creating a registration object for the device that stores the device's push token along with other details in the Telerik Platform cloud. The registration object's fields can be used to target messages to specific devices or device types.
This article is organized as follows:
For push notifications to work in your app, take the following actions:
Include the following capabilities in your manifest file (or select them from the manifest editor):
Configure push notifications by following the instructions in this MSDN article: How to authenticate with the Windows Push Notification Service (WNS) (Windows Runtime apps).
Initialize() method to initialize a device for push notifications. Before you do that, you need to ensure that the device can contact MPNS (can connect to the internet and the connection is not blocked by firewall devices).
On success, the device receives a push notification token.
PushSettings instance to specify initialization settings that are passed to MPNS. All available settings are presented in the next table.
|Property Name||Property Type||Default Value||Description|
|ChannelName||string||null||The name of the channel to use for push notifications. If null, the default channel name is used. Normally you need to set this only if you have already created a notification channel in your app outside of the Backend Services .NET SDK.|
|AutoUpdateWhenChannelChanged||bool||true||Specifies whether the device registration is automatically updated when the notification channel changes.|
|AutoBindToShellToast||bool||true||Specifies whether push notifications are bound to toast notifications automatically. If set to true, the HttpNotificationChannel.BindToShellToast() method is invoked internally.|
|AutoBindToShellTile||bool||true||Specifies whether push notifications are bound to tile updates automatically. If set to true, the HttpNotificationChannel.BindToShelTile() method is invoked internally.|
After you have successfully initialized the device, you need to register it with Telerik Platform so that you can send it notifications.
Register() method compiles all required device data and stores it in Telerik Platform:
var result = await app.WorkWith().Push().CurrentDevice.Register().ExecuteAsync();
customDeviceParameters allows you to include custom registration parameters. Later you can use them in filter expressions to target the device with specific messages.
var customDeviceParameters = new DeviceParameters(); customDeviceParameters.Add("age", "26"); customDeviceParameters.Add("City", "London"); var result = await app.WorkWith().Push().CurrentDevice.Register(customDeviceParameters).ExecuteAsync();
Once this method completes successfully, you can send notification to the device from Telerik Platform.