Worklight 6.2 - 未发送广播通知

时间:2014-12-09 05:36:49

标签: push-notification ibm-mobilefirst worklight-adapters

我们正在尝试运行推送通知的示例应用程序并进行一些修改,以使其发送广播通知,但它没有被发送。

我们也修改了PushBackendEmulator代码。模拟器成功调用submitBroadCastNotification过程,并返回以下结果:

  

服务器响应:: / -secure - {"结果":"通知发送给所有人   用户"" isSuccessful":真} /

但是,WL.Server.sendMessage方法似乎没有发送消息并返回。在自由服务器上进行彻底搜索之后,我无法看到服务器端日志,除了自由服务器上的messages.log,当调用WL.Server.sendMessage时显示以下内容。

  

ht.integration.js.JavaScriptIntegrationLibraryImplementation E.   FWLSE0227E:无法发送通知。原因:FPWSE0009E:内部   服务器错误。找不到设备[项目工作灯]

以下是适配器代码:

function submitBroadcastNotification( notificationText) {

    var notification = {};
    notification.message = {};
    notification.message.alert = notificationText;

    //notification.target = {};
    //notification.target.tagNames = ['test'];


    WL.Logger.debug("broadcast: " + notification.message.alert );

    var delayTimeOut = **WL.Server.sendMessage**("PushNotificationsApp", notification);
    WL.Logger.debug("Return value from WL.Server.sendMessage :"+ delayTimeOut);

    return {
    result : "Notification sent to all users"
    };
}

这是PushBackendEmulator代码:

public static void main(String [] args){
        String serverUrl =
                "http://208.124.245.78:9080/worklight";

        String notificationText = "Hellofrombroadcastingnotifications";
        String userId = "admin";

        notificationText = notificationText.replace(" ", "%20");
        Logger.debug("sending broadcast notification: " + notificationText);

        URL url = new URL(serverUrl
                + "/invoke?

    adapter=PushAdapter&procedure=submitBroadcastNotification&parameters=['" + userId + "','" + notificationText + "']");
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setRequestMethod("GET");
    connection.setReadTimeout(10000);
    connection.setDoOutput(true);
        Logger.debug("Connected to server");
        BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));

        String response = "";
        String inputLine;

        while ((inputLine = in.readLine()) != null)
            response+= inputLine;
        Logger.debug("response is:"+ response);
        in.close();

        Logger.debug("Server response :: " + response);

        connection.disconnect();

1 个答案:

答案 0 :(得分:0)

从PMR看你的应用程序,在我看来,你混合了基于事件源的通知和广播通知。

如果您想使用广播通知,这意味着您无法尝试强制将通知发送到任何特定的userId等,因为它不需要也不基于userIds。

默认情况下,所有设备都会自动订阅名为“push.ALL”的标签 您可以阅读有关广播通知API方法in the IBM Worklight Knowledge Center

的更多信息

这是您的应用程序的修改版本,在iOS和Android中进行了测试:https://www.dropbox.com/s/l2yk2pbvykrzfoh/broadcastNotificationsTest.zip?dl=0

基本上,我删除了与广播通知无关的任何内容:

  • 我从application-descriptor.xml
  • 中删除了push securitytest
  • 我从适配器XML和JS文件以及与基于事件源的通知相关的main.js文件中删除了任何函数。

最终结果是,在加载应用程序后,您就在应用程序内部(无需登录) 然后我在Studio>中右键单击了适配器文件夹。调用过程,并选择submitBroadcastNotification选项发送通知(“aaa”)。

在设备中,收到了通知。点击它(如果应用程序关闭)启动应用程序,然后触发公共\ js \ main.js中的WL.Client.Push.onMessage API以显示包含已接收通知的有效负载和道具的警报。

这在iOS和Android都经过测试 在加载应用程序时,我可以在LogCat和Xcode控制台中看到令牌注册。

  • 要在iOS中进行测试,您需要使用自己的pushSender密码更新application-descriptor.xml,并添加自己的apns-certificatae-sandbox.p12文件。

  • 要在Android中进行测试,请确保您已在GCM控制台中生成浏览器键并在application-descriptor.xml中使用

  • 对于这两者,请确保all requires ports and addresses并可在您的网络中访问

相关问题