Push notifications integration
This reference article covers how to set up Android, FireOS, and iOS push notifications for Xamarin.
Android
See the Android integration instructions for information on how to integrate push into your Xamarin Android app. Furthermore, you can look at the sample application to see how the namespaces change from Java to C#.
iOS
See the iOS integration instructions for information about setting up your application with push and storing your credentials on our server.
Requesting push permissions
Set up push permissions by adding the following code to the FinishedLaunching
section of your AppDelegate.cs
:
1
2
3
4
// C#
UIUserNotificationSettings settings = UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Badge | UIUserNotificationType.Alert | UIUserNotificationType.Sound, null);
UIApplication.SharedApplication.RegisterForRemoteNotifications();
UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
If you’ve implemented a custom push opt-in prompt, make sure that you’re calling the preceding code EVERY time the app runs after they grant push permissions to your app. Apps need to reregister with APNs as device tokens can change arbitrarily.
Registering push tokens
Register for your push tokens by adding the following code in the RegisteredForRemoteNotifications
method of your AppDelegate.cs
:
1
2
// C#
Appboy.SharedInstance().RegisterDeviceToken (deviceToken);
Enabling push analytics
Enable open tracking on push notifications by adding the following code to the DidReceiveRemoteNotification
method of your AppDelegate.cs
:
1
2
3
4
5
// C#
public override void DidReceiveRemoteNotification (UIApplication application, NSDictionary userInfo, Action<UIBackgroundFetchResult> completionHandler)
{
Appboy.SharedInstance().RegisterApplicationWithFetchCompletionHandler(application, userInfo, completionHandler);
}
Badge count
If badge counts are enabled, Braze will display a badge when a customer has unread notifications. By default, this number is 1. Braze will only clear the badge count when the app is opened directly from a Braze push notification. To clear the badge count, refer to Xamarin and use the following code:
1
2
// C#
UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0;