For up-to-date product documentation, see the IBM MobileFirst Foundation Developer Center.
Scenario 2: Existing applications using multiple event sources in their application
Applications using multiple event sources requires the segmentation of users based on the subscriptions.
Client
This maps to tags which segments the users/devices based on topic of interest. To migrate this in MobileFirst V8.0.0, convert this model to tag based notification.
- Initialize the MFPPush client instance in your application:
MFPPush push = MFPPush.getInstance(); push.initialize(_this);
- Implement the interface MFPPushNotificationListener and define onReceive().
@Override public void onReceive(MFPSimplePushNotification message) { Log.i("Push Notifications", message.getAlert()); }
- Register the mobile device with the push notification service.
push.registerDevice(new MFPPushResponseListener<String>(){ @Override public void onFailure(MFPPushException arg0) { Log.i("Push Notifications", "Failed to register"); } @Override public void onSuccess(String arg0) { Log.i("Push Notifications", "Registered successfully"); } });
- (Optional) Un-register the mobile device from the push notification service:
push.unregisterDevice(new MFPPushResponseListener<String>(){ @Override public void onFailure(MFPPushException arg0) { Log.i("Push Notifications", "Failed to unregister"); } @Override public void onSuccess(String arg0) { Log.i( "Push Notifications", "Unregistered successfully"); } });
- Remove WLClient.Push.isPushSupported() (if used) and use push.isPushSupported();.
- Remove the following WLClient.Push APIs since there will be no event source to subscribe to and register notification callbacks:
- registerEventSourceCallback()
- subscribe()
- unsubscribe()
- isSubscribed()
- WLOnReadyToSubscribeListener and WLNotificationListener Implementation
- Subscribe to tags:
String[] tags = new String[2]; tags[0] ="sample-tag1"; tags[1] ="sample-tag2"; push.subscribe(tags, new MFPPushResponseListener<String[]>(){ @Override public void onFailure(MFPPushException arg0) { Log.i(“Failed to subscribe"); } @Override public void onSuccess(String[] arg0) { Log.i( "Subscribed successfully"); } });
- (Optional) Unsubscribe from tags:
String[] tags = new String[2]; tags[0] ="sample-tag1"; tags[1] ="sample-tag2"; push.unsubscribe(tags, new MFPPushResponseListener<String[]>(){ @Override public void onFailure(MFPPushException arg0) { Log.i("Push Notifications", "Failed to unsubscribe"); } @Override public void onSuccess(String[] arg0) { Log.i("Push Notifications", "Unsubscribed successfully"); } });
Server
Remove the following WL.Server APIs (if used) in your adapter:
- notifyAllDevices()
- notifyDevice()
- notifyDeviceSubscription()
- createEventSource()
Complete the following steps for every application that was using the same event source:
- Set up the credentials by using the MobileFirst Operations Console. See Configure push notification settings.
We can also set up the credentials by using Update GCM settings (PUT) REST API, for Android applications or Update APNs settings (PUT) REST API, for iOS applications.
- Add the scope push.mobileclient in Scope Elements Mapping.
- Create tags to enable push notifications to be sent to subscribers. See Create tags for push notification.
- We can use either of the following methods to send notifications:
- The MobileFirst Operations Console. See Sending push notifications to subscribers.
- The Push Message (POST) REST API with userId/deviceId.
Parent topic: Native Android applications