App Push Notification
For setting up app push notifications within your app, you can follow the steps mentioned below. Choose the platform that you want to set up push notifications for.
Additional methods - Android
iZooto provides few additional methods within Android SDK to help you with customizations.
Method | Description |
---|---|
User Status | |
setSubscription | Disable iZooto from sending notifications to current device. |
Handling Notifications | |
NotificationReceivedHandler | Called when a notification is received by a device. |
NotificationOpenedHandler | Called when the notification is clicked by the user. |
setSubscription
Method
setSubscription
MethodThe user must first subscribe through the native prompt or app settings. It does not subscribe or unsubscribe the user from the app settings, it unsubscribes the user from receiving push from iZooto.
You can set the value to 'false' to opt-out users from receiving notifications via iZooto and to 'true' to opt users back into notifications.
iZooto.setSubscription(false);
Notification Handlers
NotificationReceivedHandler
This will be called when a notification is received.
public class MyApplicationName extends Application implements NotificationHelperListener {
@Override
public void onNotificationReceived(Payload payload) {
// Returns the content of Notification Payload
Log.e("Payload", payload.getTitle());
}
}
class MyApplication : Application() ,NotificationHelperListener
{
override fun onNotificationReceived(payload: Payload?) {
// Returns the content of Notification Payload
Log.e("Payload”,payload?.title.toString())
}
}
The payload fetched from here can be used to populate notification's data inside your App Notifications Inbox.
NotificationOpenedHandler
This will be called when a notification is tapped on.
class MyNotificationClass implements NotificationHelperListener
{
// This fires when a notification is opened by tapping on it.
@Override
public void onNotificationOpened(String data) {
JSONObject jsonObject =new JSONObject(data);
//Received actionType from Payload.
String actionType =jsonObject.optString("actionType");
String customKey;
String landingURL = null;
Object activityToLaunch = MainActivity.class; //Default activity to be opened
if (jsonObject != null) {
landingURL = jsonObject.optString("landingURL", null);
if (landingURL != null)
// Define code to handle the landing URL.
}
if (actionType.equalsIgnoreCase(jsonObject.optString("actionType"))) {
if (jsonObject.optString("actionID").equalsIgnoreCase("Key_Name")) {
//Key_Name would be the additional data parameter you define.
jsonObject.optString("actionID"));
activityToLaunch = ImageActvity.class; //Can change activity Name
}
// The following can be used to open an Activity of your choice.
// Replace - getApplicationContext() - with any Android Context.
// Intent intent = new Intent(getApplicationContext(), YourActivity.class);
Intent intent = new Intent(getApplicationContext(), (Class<?>) activityToLaunch);
//If the app killed in background, launches the application.
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("LandingURL", landingURL); //Can be used to send payload data from one activity to another
startActivity(intent);
// Add the following to your AndroidManifest.xml to prevent the launching of your main Activity if you are calling startActivity above.
// <activity android:name=".YourActivityName" />
}
}
}
Notification Received Handler can be used to define Deep Links within your application.
Additional methods - iOS
iZooto provides few additional methods within iOS SDK to help you with customizations.
Method | Description |
---|---|
Handling Notifications | |
onNotificationReceived | Called when a notification is received by a device |
onNotificationView | Called when the notification is clicked by the user. |
Notification Handlers
onNotificationReceived()
This method will be called when a notification is delivered to the subscriber's device.
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, iZootoNotificationActionDelegate {
func onNotificationReceived(payload: Aps) {
// Returns the content of Notification Payload.
print("Data",payload.alert?.title as Any)
}
}
It can be used to populate notification’s data inside your App Notification Inbox, if available.
onNotificationView()
This method will be called when a notification is tapped on.
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, iZootoNotificationActionDelegate {
func onOpenActionHandler(action: String) {
print("Data",action)
}
Updated over 3 years ago