【问题标题】:Passing data on subscribe using WLPush for Worklight iOS notifications使用 WLPush for Worklight iOS 通知在订阅时传递数据
【发布时间】:2013-10-01 20:46:34
【问题描述】:

我需要在订阅通知时传递数据,因此,我采用了 Module_07_04_iOSNativePush 应用程序中的示例代码,并将以下代码添加到连接方法(在 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];

这不会引发任何错误,但是,当我运行示例 PushAdapter 代码并使用以下代码添加到适配器时:

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

适配器中的结果是:

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

我希望我通过“状态”下的字典传入的变量,对吗?适配器中是否有其他方法可以获取在 [WLPush subscribe] 调用中传入的参数?

您可能会说,我对 Objective C 非常陌生,因此,不要假设对 subscribe 的调用正确完成。另外,我正在使用带有 Fix Pack 1 的 Worklight Studio 6。

【问题讨论】:

    标签: ibm-mobilefirst worklight-adapters worklight-server worklight-console


    【解决方案1】:

    状态将不包含在订阅调用期间传递的参数。您需要先获得设备订阅。设备订阅的选项对象将包含订阅期间传递的参数。

    例如。

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

    请参考以下信息中心链接

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

    【讨论】:

    • 这回答了部分问题,但是,为什么 pushit WLPushOptions 不保存这个?
    猜你喜欢
    • 1970-01-01
    • 2019-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多