Push Notification

Configuring Push in Android

To use Push Notification in your Unity application you need to configure Firebase into your application, refer to the Push Notification documentation to configure Push Notification in your application.
Also, make sure you have set up Firebase for Unity.

In case, your application is handling the push token registration and push payload we highly recommend you use the native Android methods(mentioned in the documentation above) for passing the token and the payload to the SDK.
If for whatever reason you wish to pass the push token and payload to the SDK via the Unity game Engine or C# code use the below APIs

Passing Push Token

c#
using MoEngage;

MoEngageClient.PassPushToken()

Passing Push Payload

c#
using MoEngage;
MoEngageClient.PassPushPayload()
 

We highly recommend you to use the Android native APIs for passing the push payload to the MoEngage SDK instead of the Unity/C# APIs. Unity Engine might not get initialized if the application is in the killed state which will lead to poor push reachability or delivery.

Configuring Push in iOS

APNS Certificate

First, you will have to create an APNS certificate and upload to 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.

Push Registration

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

c#
using MoEngage;

MoEngageClient.RegisterForPush();

App Target Settings

MoEngage plugin takes care of setting up the project while building it for the first time. But verify the Capability section has Push Notifications enabled along with AppGroups and Background Mode Settings as shown below:

 

AppGroups:

MoEngage plugin creates an app group for the app with format: group.<app bundle id>.moengage. Make sure the same is resolved with the Apple developer account here.

Notification Extensions

 
  • This step is only required on first-time integration OR whenever you Replace the build. If you Build and Append hereafter, this step would not be required.

MoEngagePlugin adds MoENotificationServiceExtension and MoEPushTemplateExtension target for supporting Rich Push and Push delivery tracking. Verify the Capability section has Push Notifications enabled along with AppGroups as shown below:

1e20120-Screenshot_2020-07-06_at_03.09.01.png

Add MORichNotification framework

In MoENotificationServiceExtension and MoEPushTemplateExtension target, add MORichNotification framework to Frameworks and Libraries section from Pods folder as shown below:

 
  • Minimum deployment target of MoENotificationServiceExtension and MoEPushTemplateExtension targets should be set to 10.0(or higher) and 12.0(or higher) respectively.
  • Push Templates is supported from Package [Version 1.1.0] and above.

dba3029-Screenshot_2020-07-06_at_03.09.14.png

c3740c8-ServiceExtensionTarget.png

Notification Click Observers:

MoEngage plugin triggers the PushNotifCallback event whenever a notification is clicked. This event is a common trigger for both iOS and Android platforms. Refer to the below code to set observer to the same:

c#
using MoEngage;

// Add Push Callback for MoEGameObject
MoEGameObject.PushNotifCallback += PushCallback;

//Implement the calback
public void PushCallback(object sender, PushCampaign campaign)
	{
		Debug.Log(" Event handler callback: " + campaign.platform + " \n payload:" + campaign.payload);
	}

PushCampaign structure

PushCampaign instance will have the below properties:

c#
public class PushCampaign
{
    public string platform; // ios/android
    public IDictionary<string,object> payload; // notification payload
    public bool isDefaultAction; 
    public IDictionary<string,object> clickedAction;
}

Payload Structure for clickedAction Dictionary

JSON
{
  "clickedAction": {
    "type": "navigation/customAction",
    "payload": {
      "type": "screenName/deepLink/richLanding",
      "value": "",
      "kvPair": {
        "key1": "value1",
        "key2": "value2",
        ...
      }
    }
  }
}

platform - Native platform from which callback is triggered. Possible values - androidios
isDefaultAction - This key is present only for the Android Platform. It's a boolean value indicating if the user clicked on the default content or not. true if the user clicks on the default content else false.
clickedAction - Action to be performed on notification click.
clickedAction.type - Type of click action. Possible values navigation and customAction. Currently, customAction is supported only on Android.
clickAction.payload - Action payload for the clicked action.
clickedAction.payload.type - Type of navigation action defined. Possible values screenNamedeepLinkrichLanding. Currently, in the case of iOS, richlanding and deep-link URL are processed internally by the SDK and not passed in this callback therefore possible value in case of iOS is only screenName.
clickAction.value - value entered for navigation action or custom payload.
clickAction.kvPair - Custom key-value pair entered on the MoEngage Platform.
payload - Complete campaign payload.

Android Payload

If the user clicks on the default content of the notification the key-value pair and campaign payload can be found inside the payload key. If the user clicks on the action button or a push template action the action payload would be found inside clickedAction.
You can use the isDefaultAction key to check whether the user clicked on the default content or not and then parse the payload accordingly.

iOS Payload

In the case of iOS, you would always receive the key-value pairs with respect to clicked action in clickedAction property. Refer to this link for knowing the iOS notification payload structure.

Was this article helpful?
0 out of 0 found this helpful