Worklight 6.2-未发送广播通知 [英] Worklight 6.2 - Broadcast notification not being sent

查看:105
本文介绍了Worklight 6.2-未发送广播通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正尝试运行示例应用程序以进行推送通知,并进行一些修改,以使其能够发送广播通知,但未发送出去.

We are trying to run the sample app for push notifications with some modification to get it to send out a broadcast notification, but it is not getting sent.

我们还修改了PushBackendEmulator代码.仿真器成功调用了SubmitBroadCastNotification过程,并返回以下结果:

We have modified the PushBackendEmulator code as well. The emulator invokes the submitBroadCastNotification procedure successfully and the following result is returned:

服务器响应::/ -secure-{"result":将通知发送给所有人 users," isSuccessful:true} /

Server response :: /-secure-{"result":"Notification sent to all users","isSuccessful":true}/

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

However, it appears the WL.Server.sendMessage method is not sending the message and returns. I am not able to see the server side logs either after a thorough search on the liberty server except for the messages.log on the liberty server which shows the following when WL.Server.sendMessage is called.

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

ht.integration.js.JavaScriptIntegrationLibraryImplementation E FWLSE0227E: Failed to send notification. Reason: FPWSE0009E: Internal server error. No devices found [project worklight]

这是适配器代码:

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代码:

Here is the PushBackendEmulator code:

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();

推荐答案

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

Looking at your application from the PMR, it seems to me like you have mixed both event source-based notifications and broadcast notifications.

如果您要使用广播通知,这意味着您不能尝试强行将通知发送给任何特定的userId,等等,因为它既不需要也不基于userId.

If you want to use Broadcast notifications, this means you cannot try imposing sending the notification to any specific userId, etc as it is not needed nor based on userIds.

默认情况下,所有设备都自动订阅名为"push.ALL"的标签.
您可以阅读有关广播通知API方法的更多信息在IBM Worklight知识中心.

By default, all devices are auto-subscribed to a tag called "push.ALL".
You can read more about broadcast notifications API methods in the IBM Worklight Knowledge Center.

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

This is a modified version of your application, tested in iOS and Android: https://www.dropbox.com/s/l2yk2pbvykrzfoh/broadcastNotificationsTest.zip?dl=0

基本上,我从中剥离了与广播通知无关的所有内容:

Basically, I stripped away from it anything not related to broadcast notifications:

  • 我从application-descriptor.xml中删除了推送安全性测试
  • 我从适配器XML和JS文件以及main.js文件中删除了与基于事件源的通知相关的任何功能.

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

The end result is that after the app is loaded, you are right inside the application (no login).
I then right-clicked the adapter folder in Studio > invoke procedure, and selected the submitBroadcastNotification option to send the notification ("aaa").

在设备中,收到通知.轻敲它(如果应用程序已关闭),将启动该应用程序,然后触发common \ js \ main.js中的WL.Client.Push.onMessage API,以显示包含所接收通知的有效负载和内容的警报.

In the device, a notification was received. Tapping it (if the app is closed) launches the application, which then triggers the WL.Client.Push.onMessage API in common\js\main.js to display alerts containing the payload and props of the received notification.

这已在iOS和Android上进行了测试.
在加载应用程序时,我可以在LogCat和Xcode控制台中看到令牌注册.

This was tested in both iOS and Android.
As the application was loading, I could see in LogCat and Xcode console the token registration.

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

  • To test this in iOS, you will need to update application-descriptor.xml with your own pushSender password and add your own apns-certificatae-sandbox.p12 file.

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

To test in Android, make sure you are have generated a browser key in the GCM console and are using it in application-descriptor.xml

对于两者,请确保

For both, make sure that all requires ports and addresses and accessible in your network

这篇关于Worklight 6.2-未发送广播通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆