Your first notification

You should now be able to start Batch SDK and to receive push notifications.
As Xamarin binds the native APIs, our native documentation is where you will find information on how to integrate Batch in your application.

Starting the SDK

Android

Batch needs to be in the Application subclass. Your project may already have one. If it does not, create an MyApplication class and paste the example in it.

[Application]
public class MyApplication: Application
{
    public MyApplication(IntPtr handle, JniHandleOwnership ownership) : base(handle, ownership) {}

    public override void OnCreate()
    {
        base.OnCreate();

        Batch.SetConfig(new Config("<Android API Key>"));
        RegisterActivityLifecycleCallbacks(new BatchActivityLifecycleHelper());
    }
}

iOS

In your AppDelegate.cs:

public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
    // ...

    Batch.StartWithAPIKey("<iOS API Key>");
    BatchPush.RefreshToken();
    BatchPush.RequestNotificationAuthorization();

    // This line manually prints the Installation ID in Xamarin's logs
    // as Visual Studio sometimes fails to display iOS device logs.
    System.Console.Out.WriteLine("Batch Installation ID: " + BatchUser.InstallationID);

    // ...
}

Obtaining your device token on iOS

Note: Push notifications must be configured in the project by adding the required entitlement

You can find your device's token using the debug tool or locating the token Batch posts to the logs.

Here is what you will find in the logs after opening your app:

Installation ID: <Installation ID>
Push token (Apple Push Production): <push token>

Based on your Provisioning Profile, the token shown in the console will be Development ("Sandbox/Development") or Production ("Production").

Obtaining your device token on Android

Note: Batch doesn't come with Firebase builtin: Firebase Cloud Messaging should be added to your Xamarin project and configured for push notifications to work

You can find your device's token using the debug tool or locating the token Batch posts to the logcat (see here to know more):

Batch   : Installation ID: <Installation ID>
Batch.Push: Registration ID/Push Token (FCM): <your device token>

Sending a test push

You can send test notifications to your device with a push token. In the push notification creation form, click the ⚙️ and copy your push token in the corresponding field. Click "Send a test".

Test push