Customizing notifications

Batch allows you to customize your notifications adding specific keys to the payload or by setting some configuration in native code.

Advanced notification configuration is highly OS-specific and requires implementation at a lower level than React-Native.
Therefore, you might find what you want in the native documentations for each OS:

Small push notification icon

In order to make sure that users understand that your notifications come from your app, you need to setup a Small Icon and Notification Color. An icon can be generated using Android Studio's asset generator: as it will be tinted and masked by the system, only the alpha channel matters and will define the shape displayed. It should be of 24x24dp size. If your notifications shows up in the system statusbar in a white shape, this is what you need to configure.

This can be configured in the manifest as metadata in the application tag:

<!-- Assuming there is a push_icon.png in your res/drawable-{dpi} folder -->

<manifest ...>
    <application ...>
        <meta-data
            android:name="com.batch.android.push.smallicon"
            android:resource="@drawable/push_icon" />

        <!-- Notification color. ARGB but the alpha value can only be FF -->
        <meta-data
            android:name="com.batch.android.push.color"
            android:value="#FF00FF00" />

Showing foreground notifications on iOS

Notification behaviour when your app is in foreground depends on the OS:

  • On Android, the SDK will show notifications while the app is in foreground.
    If a Mobile Landing is attached, the SDK will display it immediatly unless this has explicitly been disabled using native code.
  • On iOS, the SDK follows iOS' default behavior which is not to display the notifications while the app is in foreground. This can be configured. If notifications are shown while the app is in foreground, Mobile Landings won't be immediatly shown.

8.0.0 The SDK exposes a method on BatchPush to change the behaviour on iOS:

import { BatchPush } from '@batch.com/react-native-plugin';

// Make iOS behave like Android
BatchPush.setShowForegroundNotification(true);

Note: this requires your app to use BatchUNUserNotificationCenterDelegate as described in the sdk integration. If you made your own UNUserNotificationCenterDelegate subclass, this API will not do anything and you will have to implement this manually.

If you are using a version of the sdk < 8.0.0 you still can change this behavior but you will need to update your AppDelegage.m :


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    ...
    [BatchUNUserNotificationCenterDelegate registerAsDelegate];
    [BatchUNUserNotificationCenterDelegate sharedInstance].showForegroundNotifications = true;
    return YES;
}

Adding notification actions

Notification actions are supported but they integration differ greatly between iOS and Android. Please see the native documentations for more info:

Overriding the notification channel on Android

It is possible to override the default notification channel on Android either globally on a per notification basis.

As this is an operation that needs to be done by native code in the background when React-Native isn't running, please follow our native channels documentation.