IBM Worklight 5.0.6.1 - 关闭电话/应用程序时未收到推送通知 [英] IBM Worklight 5.0.6.1 - Not getting Push Notifications when phone/app is closed

查看:18
本文介绍了IBM Worklight 5.0.6.1 - 关闭电话/应用程序时未收到推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Worklight 混合应用程序,其中包含在 android 中运行的基本推送通知.如果应用程序正在运行并且在推送通知时处于焦点,则它的行为与我预期的完全一样.我的应用程序中的通知回调被调用,并弹出一个 SimpleDialog.一切顺利.

I have a Worklight hybrid app with basic push notification working in android. If the app is running and in focus when the notification is pushed, it behaves exactly as I would expect. The notification callback in my app is called, and it pops up a SimpleDialog. All Good.

如果我通过单击主页按钮关闭应用程序,并且有新消息到达,我会在 Android 通知区域中看到通知,当我单击 android 通知列表中的项目时,该项目从列表(但应用程序没有重新成为焦点)如果我然后从应用程序菜单启动我的应用程序,它就在我离开它的地方,并且显示 SimpleDialog.(我的通知处理程序被调用)大部分都很好,但是当我在 android 通知列表中选择通知时,我希望应用程序成为焦点.

If I dismiss the app by clicking on the Home Button, and a new message arrives, I see the notification in the Android notification area, and when I click on the item in the android notification list, the item gets dismissed from the list (but the app does not come back into focus) If I then launch my app from the Apps menu, it is sitting where I left it and the SimpleDialog is showing. (my notification handler was called) Mostly good, but I expected the app to come into focus when I selected the notification in the android notification list.

如果我通过单击后退按钮关闭应用程序,并且有新消息到达,我会在 Android 通知区域中看到通知,当我单击 android 通知列表中的项目时,该项目从列表(但应用程序没有重新成为焦点)如果我然后从应用程序菜单启动我的应用程序,它会重新启动应用程序(我必须再次登录)并且我的通知处理程序永远不会被调用.不太好.

If I dismiss the app by clicking on the Back Button, and a new message arrives, I see the notification in the Android notification area, and when I click on the item in the android notification list, the item gets dismissed from the list (but the app does not come back into focus) If I then launch my app from the Apps menu, it launches the app fresh (I have to log in again) and my notification handler is never called. Not so good.

如果我在发送通知时强制停止应用程序或关闭手机(但保留订阅),则通知永远不会显示在手机上.当我重新启动手机时,我在 Android 通知区域中没有看到它,并且当我启动应用程序时,我的应用程序中的通知处理程序永远不会被调用.非常糟糕.

If I force stop the app, or turn the phone off while the notification is being sent (but leave the subscription in place), the notification never shows up on the phone. I don't see it in the Android Notification area when I restart the phone, and the notification handler in my app is never called when I launch the app. Very bad.

这是预期的行为吗?

我使用的是 Worklight 5.0.6.1,并且我在平台 4.2.2 的 Android 模拟器和平台 4.1.2 的物理手机上看到了这种行为

I'm using Worklight 5.0.6.1, and I've seen this behavior on Android emulator at platform 4.2.2 and a physical phone at platform 4.1.2

EDT:添加代码.

适配器:

WL.Server.createEventSource({
    name : "MyPushEventSource",
    securityTest: "MyApp-strong-mobile-securityTest"
});

function submitNotification(userId) {

    var userSubscription = WL.Server.getUserNotificationSubscription(
            'MyPushNotification.MyPushEventSource', userId);

    if (userSubscription == null) {
        return {
            result : "No subscription found for user :: " + userId
        };
    }

    var notification = WL.Server
            .createDefaultNotification("There's work to be done!", 1, {});

    WL.Server.notifyAllDevices(userSubscription, notification);

    return {
        result : "Notification sent to user :: " + userId
    };
}

在应用中:

WL.Client.Push.onReadyToSubscribe = function() {

    var pushSubscribe_Success_Callback = function(response) {
        WL.Logger.debug("Enter: pushSubscribe_Success_Callback");
    };

    var pushSubscribe_Fail_Callback = function(response) {
        WL.Logger.debug("Enter: pushSubscribe_Fail_Callback");
    };

    var pushNotificationReceived = function(props, payload) {

        WL.SimpleDialog.show("Notification", props.alert, [
                { text : "OK" }]);
    };

    WL.Client.Push.registerEventSourceCallback("myPush",
            "MyPushNotification", "MyPushEventSource",
            pushNotificationReceived);

    if (!WL.Client.Push.isSubscribed("myPush")) {

        WL.Client.Push.subscribe("myPush", {
            onSuccess : pushSubscribe_Success_Callback,
            onFailure : pushSubscribe_Fail_Callback
        });
    }
 };

正如我所说,如果应用程序处于焦点,这一切都可以顺利进行,所以我知道我已经正确设置了 Google 消息传递帐户和密钥.但出于某种原因,如果应用在发布通知时未处于焦点中,我会看到意外的结果.

As I said, if the app is in focus, this all works without a hitch, so I know I have the Google messaging account and keys set up correctly. But for some reason I'm seeing unexpected results if the app isn't in focus when the notification is published.

推荐答案

好的.我花了很长时间才弄明白这个问题,所以如果有人关注,问题就在这里:

OK. It took me long enough to figure this one out, so in case anyone follows, here is the problem:

我通过打开 [android project]/res/values/strings.xml 并更改 app_name 的值来重命名应用.

I had renamed the app by opening [android project]/res/values/strings.xml and changing the value of app_name.

这会导致应用在选择推送通知时无法启动.

That causes the app to not launch when a push notification for the app is selected.

我通过将 app_name 改回其原始值并为友好名称添加一个名为 app_label 的新字符串来解决此问题.然后我进入 AndroidManifest.xml,并将 android:label="@string/app_name" 的 2 个实例更改为: android:label="@string/app_label" 和 sha-zam!我的应用有一个友好的名称,点击通知即可启动它.

I fixed this by changing app_name back to its original value, and adding a new String named app_label for the friendly name. I then went into AndroidManifest.xml, and changed the 2 instances of android:label="@string/app_name" to: android:label="@string/app_label" And sha-zam! My app had a friendly name AND clicking on notifications launched it.

为了更好的衡量,我将 strings.xml 中的 push_notification_title 修改为友好名称,这改善了通知的显示并且没有中断应用程序的启动.

For good measure I modified push_notification_title in strings.xml to be the friendly name, and that improved the display of the notification and did not break the launching of the app.

这篇关于IBM Worklight 5.0.6.1 - 关闭电话/应用程序时未收到推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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