简体   繁体   English

如果应用已打开,则离子推送通知不起作用

[英]Ionic push notification is not working if app is open

I am able to send push form apps.ionic.io and from postman when app is on background or screen is locked but not able to send notification when app is open. 当应用程序在后台或屏幕被锁定时,我能够发送推送表单apps.ionic.io并从邮递员发送,但在应用程序打开时却无法发送通知。 My code is as in run 我的代码运行中

    var io = Ionic.io();
            var push = new Ionic.Push({
               "onNotification": function(notification) {
            alert('Received push notification!');
          },
           "pluginConfig": {
                    "android": {
                        "icon": "ic_stat_icon"
                    }
                },
          "debug": true
        });
 push.register(function(token) {
      console.log("registered");
      console.log("Device token:",token.token);
    });

and in controller 并在控制器中

 $ionicPush.register( {
    canShowconsole.log: true, //Can pushes show an console.log on your screen?
    canShowAlert: true, //Can pushes show an alert on your screen?
    canSetBadge: true, //Can pushes update app icon badges?
    canPlaySound: true, //Can notifications play a sound?
    canRunActionsOnWake: true, //Can run actions outside the app,
    onNotification: function(notification) {
       console.log(notification);
     // Handle new push notifications here
     alert('Received push notification!');
     return true;
   }
        }).then(function(t) {
    return $ionicPush.saveToken(t);
  }).then(function(t) {
    console.log('Token saved:', t.token);
  });

Try this thing in your app.js or controller file. 在您的app.js或控制器文件中尝试一下。

$rootScope.$on('cloud:push:notification', function(event, data) {
      var msg = data.message;
      console.log(msg);
      // alert(msg.title + ': ' + msg.text);

      var alertPopup = $ionicPopup.alert({
            title: msg.title,
            template: msg.text.toString()
        });

    });

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

相关问题 离子推送通知无法打开应用,并且是单行 - Ionic push notification doesn't open app and is single line 当用户点击推送通知时,在ionic应用程序中打开特定视图 - Open a specific view in ionic app when user taps on push notification android 离子推送通知不打开后台应用程序 - Ionic push notification does not open the background app on android 在离子应用程序中实现推送通知 - implementing push notification in ionic app 当应用程序无法在后台运行时,如何在点击推送通知中打开网址 - how to open url on click push notification when app is not working in background 离子1信号有一种方法可以知道从背景到前景打开应用程序或启动应用程序时是否有推送通知 - ionic 1 onesignal is there a way to know if there is a push notification when open app from background to foreground or launching app Ionic 2应用程序每次收到推送通知时都会停止 - Ionic 2 app stops everytime it received a push notification 在Ionic应用程序中看不到GCM推送通知图标 - GCM Push Notification icon is not visible in Ionic app Ionic 2推送通知在Android版本4中不起作用 - Ionic 2 push notification not working in android version 4 离子推送通知在Android设备上不起作用 - Ionic push notification not working on android device
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM