Push Notifications

Configuring Push Notifications in Android

Adding Push Related Meta Data

Refer to Push Notification documentation and add all the required meta-data for push notifications to work.

Configuring Firebase

Once the required meta data is added refer to Configuring FCM documentation to configure Firebase in your application.

🚧

Please ensure you have added the appropriate FCM library dependency provided by Google in your app along with the required plugins and google-services.json file.

Configuring Push Notifications in iOS

APNS Certificate :

First you will have to create an APNS certificate and upload in the dashboard to be able to send push notifications in iOS. Follow the steps below to do that :

*Follow the links on each step to complete it.

Adding Push Entitlement to your Project :

Once the APNS Certificate is uploaded, enable Push Entitlement in the Xcode project. For that select your app target, then go to Capabilities . Here enable the Push Notifications capability for your app as shown below :

1624

Uninstall Tracking :

We make use of silent pushes to track uninstalls. For tracking uninstalls of all the user, enable Remote Notification background mode in app capabilities for the same as shown below :

1620

Push Registration :

After this you will have to register for push notification by using registerForPushNotification method of the plugin as shown below :

var moe = new MoECordova.init();
moe.registerForPushNotification();

📘

AppDelegate Remote notification methods will not be called

Plugin gets all the remote notification related callbacks, therefore you won't receive any of them in your AppDelegate. Therefore, you will have to add observers for the notifications provided by plugin instead.

Plugin provides Notification Observers for remote notification related methods. This is not a mandatory step, do it only if want to make use of these callbacks. First import MOEHelperConstants.h to your AppDelegate, and after that add your AppDelegate as observers for these notifications as shown below :

#import "AppDelegate.h"
#import "MainViewController.h"
#import <MoEngage/MoEngage.h>

@implementation AppDelegate

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
  // Adding Observers for MoEngage SDK notifications related to remote notifications
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidReceiveRemoteNotification:) name:MoEngage_Notification_Received_Notification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidRegisterForRemoteNotification:) name:MoEngage_Notification_Registered_Notification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidRegisterForUserSettings:) name:MoEngage_Notification_UserSettings_Registered_Notification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidFailToRegisterForRemoteNotification:) name:MoEngage_Notification_Registration_Failed_Notification object:nil];
    
    self.viewController = [[MainViewController alloc] init];
    return [super application:application didFinishLaunchingWithOptions:launchOptions];
}

#pragma mark- MoEngage Notification Observer methods

-(void)applicationDidReceiveRemoteNotification:(NSNotification *)notification{
    NSLog(@"Notification payload :  %@",notification.userInfo);
}


-(void)applicationDidRegisterForRemoteNotification:(NSNotification *)notification{
    NSData* deviceToken = notification.userInfo[MoEngage_Device_Token_Key];
    NSLog(@"notif info :  %@ And deviceToken : %@",notification, deviceToken);
}

-(void)applicationDidRegisterForUserSettings:(NSNotification *)notification{
    
    UIUserNotificationSettings *settings = notification.userInfo[MoEngage_Notification_Settings_Key];
    NSLog(@"settings info :  %@ And settings : %@",notification,settings);
}

-(void)applicationDidFailToRegisterForRemoteNotification:(NSNotification *)notification{
    NSLog(@"settings info :  %@",notification);
}

@end

Callback in JavaScript on Notification Click

To get a callback in javascript on notification click you need to register for a click listener as shown below.

Minimum Plugin version required : 3.0.0

var moe = new MoECordova.init();
        moe.on('onPushClick', function(data) {
          //add logic here
        });

What’s Next