Tag-based notifications in native iOS applications

improve this page | report issue

Overview

Tag notifications are notification messages that are targeted to all the devices that are subscribed to a particular tag. Tags represent topics of interest to the user and provide the ability to receive notifications according to the chosen interest.

Setting up tags

Tags are defined in the application-descriptor.xml file:
<nativeIOSApp xmlns="http://www.worklight.com/native-ios-descriptor" bundleId="com.REPLACE-WITH-BUNDLE-ID" id="NativeiOSTagNotifications" platformVersion="7.0.0.00.20150312-0731" version="1.0">
...
...
...
<tags>
    <tag>
        <name>my tag 1</name>
        <description>About my tag 1</description>
    </tag>
    <tag>
        <name>my tag 2</name>
        <description>About my tag 2</description>
    </tag>
</tags> 

Tag-based notifications API methods

Client-side methods:

  • [[WLPush sharedInstance]subscribeTag:tagName :options)] Subscribes the device to the specified tag name.
  • [[WLPush sharedInstance]unsubscribeTag:tagName :options)] Unsubscribes the device from the specified tag name.
  • [WLPush sharedInstance]isTagSubscribed:tagName] Returns whether the device is subscribed to a specified tag name.

Common API methods for tag-based and broadcast notifications

Client-side API:

When a notification is received by a device, the didReceiveRemoteNotification method in the app delegate is called. The logic to handle the notification should be defined here.
 
-(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo{
    NSLog(@"Received Notification %@",userInfo.description);
}
  • userInfo - A JSON block that contains the payload field. This field holds other data that is sent from the MobileFirst Platform server. It also contains the tag name for tag and broadcast notification. The tag name appears in the tag element. For broadcast notification, the default tag name is Push.ALL.
 [[WLPush sharedInstance] setOnReadyToSubscribeListener:readyToSubscribeListener]; 
  • This method registers a listener to be used for push notifications. This listener should implement the OnReadyToSubscribe() method.

Server-side API

  • WL.Server.sendMessage(applicationId,notificationOptions) This method submits a notification based on the specified target parameters and takes two mandatory parameters:
    • applicationId - (mandatory) The name of the MobileFirst application
    • notificationOptions - (mandatory) A JSON block containing message properties
For a full list of message properties, refer to the WL.Server.sendMessage API in the API reference documentation.

Sample application

Before running the application, check the adapter's PushAdapter-impl.js file and verify that the WL.Server.sendMessage() method use the correct application name. The correct application name can be determined from the id attribute in application-descriptor.xml. Click to download the Studio project Click to download Native project
Last modified on November 09, 2016