简体   繁体   English

状态栏中的IBM MFP推送通知(Cordova)

[英]IBM mfp push notifications in status bar (Cordova)

Hi i'm trying to show Push Notifications in Android Status Bar . 嗨,我正在尝试在Android状态栏中显示推送通知 I'm using ibm-mfp-push plugin and this code: 我正在使用ibm-mfp-push插件和以下代码:

onDeviceReady: function() {
        app.receivedEvent('deviceready');

          BMSClient.initialize("xxxxx","xxxxx");

        MFPPush.registerDevice({}, function(data){

            alert("Success ::" + data)
        }, function(error){
            alert("Failure ::" + error);
        }); 

        var notificationsCallback = function(notification){
            alert("Incoming notification :: " + JSON.stringify(notification))           
        };

        MFPPush.registerNotificationsCallback(notificationsCallback);

    }

I recieve notifications correctly but i have no idea how show this notifications in status bar. 我可以正确接收通知,但不知道如何在状态栏中显示此通知。 Any ideas? 有任何想法吗?

Thank you 谢谢

In case you application was running when remote notification arrived it will not be displayed automatically in notification shade since it will be immediately processed by application. 如果您的应用程序在远程通知到达时正在运行,它将不会自动在通知栏显示,因为它将由应用程序立即处理。 You will see notification in the notification shade only incase application was not running when notification has arrived. 仅当通知到达时应用程序未运行时,您才会在通知阴影中看到通知。

That said, you can add you own logic to add items to notification shade once remote notification was received. 也就是说,您可以添加自己的逻辑,以便在收到远程通知后将项目添加到通知栏。 You need to add this logic in your notificationsCallback. 您需要在notificationsCallback中添加此逻辑。 You can use an existing local-notifications plugin ( https://www.npmjs.com/package/de.appplant.cordova.plugin.local-notification ) or implement it on your own with https://developer.android.com/reference/android/app/Notification.Builder.html 您可以使用现有的本地通知插件( https://www.npmjs.com/package/de.appplant.cordova.plugin.local-notification )或通过https://developer.android.com自行实现/reference/android/app/Notification.Builder.html

I already found the solution. 我已经找到了解决方案。 Sorry if I was unclear on the question. 抱歉,如果我不清楚这个问题。 My problem was that I could not get notifications appear in the notification shade. 我的问题是我无法在通知栏显示通知。

When the application is in the foreground notifications appears to me as if javascript alert and when the application is in the background nothing appears until put in the foreground. 当应用程序处于前台时,通知就好像是JavaScript警报一样出现;当应用程序处于后台时,什么都不会出现,直到将其放在前台为止。

I tried to use various local notification plugins but when the event onDeviceReady is fullfiled these plugins are not loaded. 我尝试使用各种本地通知插件,但是当事件onDeviceReady提交满时,这些插件不会加载。

For those who do not know the plugin I leave some documentation: https://www.npmjs.com/package/ibm-mfp-push 对于那些不了解插件的人,我留下了一些文档: https : //www.npmjs.com/package/ibm-mfp-push

The solution is to add in the onDeviceReady event this: 解决方案是在onDeviceReady事件中添加以下内容:

CDVMFPPush.setIgnoreIncomingNotifications(boolean ignore); CDVMFPPush.setIgnoreIncomingNotifications(布尔忽略); (being ignore == true) (被忽略== true)

That function is described in documentation as: 该功能在文档中描述为:

By default, push notifications plugin handles all incoming Push Notification by tunneling them to JavaScript callback. 默认情况下,推送通知插件通过将所有传入的推送通知通过隧道传输到JavaScript回调来处理。 Use this method to override the plugin's default behavior in case you want to manually handle incoming push notifications in native code. 如果要手动处理本机代码中的传入推送通知,请使用此方法覆盖插件的默认行为。

BMSClient is a singleton that serves as an entry point to bluemix client-server communication. BMSClient是一个单例,它充当bluemix客户机-服务器通信的入口点。 In my case I use it to initialize the client especifying two parameters: 在我的情况下,我使用它来初始化指定两个参数的客户端:

BMSClient.initialize("APPROUTE","APPGUID"); BMSClient.initialize(“ APPROUTE”,“ APPGUID”);

Thank you for your answers. 谢谢您的回答。 Happy to belong to this great community. 很高兴加入这个伟大的社区。

regards 问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM