Configuring Your Application to Receive Push Notifications
Mobile Suite enables customers to set up the application to receive push notifications.
To prepare your mobile project to receive push notifications
1. Open your application model and locate the Application node.
4. Open the application_name AppControllerImpl.java class of your mobile project and override the onDeviceRegistered(String), onMessage(PushNotification), and onStartAppFromPushNotification(PushNotification) methods as follows:
public void onDeviceRegistered(final String newPushUID) {
String pushtoken = deviceRegistrationId;
if (runningOnIOS()) {
// converting the ios push token as it might come formatted
// <.... .... .... ....>
final StringTokenizer tokenizer = new StringTokenizer(
deviceRegistrationId, "/<> ");
final StringBuffer iosToken = new StringBuffer();
while (tokenizer.hasMoreElements()) {
iosToken.append((String) tokenizer.nextElement());
}
pushtoken = iosToken.toString();
}
// register the device pushtoken within the backend system the
// app will receive push notifications from. You need to call a service
// provided by the backend system.
// this.registerForPushNotification(pushtoken, this.username)
}
public void onMessage(final PushNotification notification) {
final String message = notification.getMessage();
if (message != null) {
// present message to the user
}
super.onMessage(notification);
}
public void onStartAppFromPushNotification(
final PushNotification notification) {
// process push notification
final String taskId = (String) notification.getParams().get("taskID");
if (taskId != null) {
// present task with taskId to the user
}
}
5. Configure your iOS and/or Android multibuilds to build your application with the correct signing required for push notifications. For more information, see Using webMethods Mobile Designer.
Related Topics