0
votes

I need to pass data on subscribing to a notification, so, I've taken the example code in Module_07_04_iOSNativePush app and added the following code to the connect method (in ViewController.m):

NSDictionary *dic = [[NSDictionary alloc] initWithObjectsAndKeys:
                     @"userName", @"DoronK",
                     @"password", @"testPwd", nil];
id pushit = [WLPushOptions new];
[pushit addSubscriptionParameter:@"test" :@"Test1"];
[pushit addSubscriptionParameters:dic];
[[WLPush sharedInstance] subscribe:readyToSubscribeListener.alias: pushit :connectListener];

This does not throw any errors, but, when I run the example PushAdapter code, and adding to the adapter using this:

var usub = 'json:'+JSON.stringify(userSubscription);
...
return { result: "Notification sent to user :: " + userId + 
  ", wait " + waittime + " before sending another. UserSub:" + usub};

The result in the adapter is:

{
  "isSuccessful": true,
  "result": "Notification sent to user :: worklight, wait 0 before sending another.    
UserSub:json:{\"userId\":\"worklight\",\"state\":{}}"
}

I would expect the variables that I passed in via the dictionary under "state", correct? Is there another way in the adapter to get the parameters that were passed in on the [WLPush subscribe] call?

As you can probably tell, I am VERY new to Objective C, so, don't assume the call to the subscribe is done correctly. Also, I'm using Worklight Studio 6 with Fix Pack 1.

1

1 Answers

1
votes

The state will not contain the parameters passed during subscribe call. You need to first get the device subscription. The options object of the device subscription will contain the parameters passed during subscribe.

For eg.

var deviceSubscriptions=userSubscription.getDeviceSubscriptions(); var usub = 'json:'+JSON.stringify(deviceSubscriptions[0]);

Please refer to the following infocenter link

http://pic.dhe.ibm.com/infocenter/wrklight/v6r0m0/topic/com.ibm.worklight.help.doc/apiref/r_method_usersubscription_getdev.html