Skip to content

Notification Setup

This setup allows you to connect NearIT native notifications to your common content handler.

Android

In Android you can detect notifications being tapped, implementing the OnPostCreate and the OnNewIntent methods in you Android launcher activity. Here's how you should do it:

protected override void OnPostCreate(Bundle savedInstanceState)
{
    base.OnPostCreate(savedInstanceState);
    OnNewIntent(Intent);
}

protected override void OnNewIntent(Intent intent)
{
    base.OnNewIntent(intent);
    NearBridgeDroid.ParseIntent(intent);
    // you will receive the Near content in your common Bridge implementation
}

iOS

On iOS, you can detect notifications being tapped or being shown while the app is open, implementing the WillPresentNotification and DidReceiveNotificationResponse methods of your notification delegate. You must also ask for notification permissions.

Here's how you should do it:

public class AppDelegate {
    // Inside your iOS AppDelegate.cs
    public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
    {
        // request notification authorization
        UNUserNotificationCenter.Current.RequestAuthorization(UNAuthorizationOptions.Alert, (approved, err) => {

        });
        // set a notification delegate
        UNUserNotificationCenter.Current.Delegate = new UserNotificationDelegate();
    }
}
// Create a delegate class (even inside the same file)
public class UserNotificationDelegate : UNUserNotificationCenterDelegate
{
    public UserNotificationDelegate() {}

    public override void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action<UNNotificationPresentationOptions> completionHandler)
    {
        completionHandler(UNNotificationPresentationOptions.Alert);
    }

    public override void DidReceiveNotificationResponse(UNUserNotificationCenter center, UNNotificationResponse response, Action completionHandler)
    {
        NearBridgeiOS.ParseContentFromResponse(response);
        // you will receive the Near content in your common Bridge implementation
    }
}