Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Push notification 应用程序处于后台时的ngCordova/Ionic推送通知_Push Notification_Ionic Framework_Pushsharp_Phonegap Pushplugin_Ngcordova - Fatal编程技术网

Push notification 应用程序处于后台时的ngCordova/Ionic推送通知

Push notification 应用程序处于后台时的ngCordova/Ionic推送通知,push-notification,ionic-framework,pushsharp,phonegap-pushplugin,ngcordova,Push Notification,Ionic Framework,Pushsharp,Phonegap Pushplugin,Ngcordova,我目前正在使用ionic/ngcordova构建一个android应用程序。我即将实现推送通知。我已经将推送通知实现为一个服务,它是在app.run(function(){..})阶段注入的。注册部分工作,我收到一个包含regid的回调。此外,当应用程序处于活动状态时,将引发事件并接收通知 我遇到的问题是,当应用程序进入后台时,根本不会收到通知。我希望在应用程序不运行或类似的情况下会发出本地通知,但绝对不会发生任何事情,这很奇怪 在过去的几天里,我一直在网络上寻找解决方案,但我找不到任何能向我表

我目前正在使用ionic/ngcordova构建一个android应用程序。我即将实现推送通知。我已经将推送通知实现为一个服务,它是在
app.run(function(){..})
阶段注入的。注册部分工作,我收到一个包含
regid
的回调。此外,当应用程序处于活动状态时,将引发事件并接收通知

我遇到的问题是,当应用程序进入后台时,根本不会收到通知。我希望在应用程序不运行或类似的情况下会发出本地通知,但绝对不会发生任何事情,这很奇怪

在过去的几天里,我一直在网络上寻找解决方案,但我找不到任何能向我表明它应该起作用的东西

以下是我的应用程序中的my notificationService.js

app.factory('notificationService', ['$cordovaPush', function($cordovaPush){

  var dataFactory = {};

  //
  // When the device is ready and this service has been plumbed in...
  document.addEventListener("deviceready", function(){

      console.log("initializing push notifications...");

      _register();

  }, false);


  //
  // Registers the device for push notifications...
  var _register = function(){

      var config = {};

      if ( device.platform == 'android' || device.platform == 'Android' || device.platform == "amazon-fireos" ){

          // TODO: centralise this value as it can change...
          config = {
              senderID: "448168747432",
              ecb: "onNotificationGCM"
          };

      }else {
          // iOS
          config = {
              "badge":"true",
              "sound":"true",
              "alert":"true"
          };

          // Can add the following property to the config object to raise a callback with the information if need be...
          // "ecb": "onNotificationRegisterAPN"
      }

      $cordovaPush.register(config).then(function(result){

                    //
                    // Typically returns "ok" for android and devicetoken for iOS
          console.log(result);

      });
  };

    window.onNotificationGCM = function(result){

        console.log(result);

        /*
         I get called when the app is in the foreground, but nothing happens when the app is in the background.
        */

    };

  dataFactory.register = _register;

  return dataFactory;
}]);
如果有帮助的话,我正在通过.net应用程序使用PushSharp来传递通知。任何帮助都将不胜感激

更新:我正在使用以下框架/库:

  • 离子骨架1.2.14-beta6
  • 科尔多瓦4.2.0
  • 插件

对于像我这样已经拔了几天头发的其他人来说,解决方案非常简单……我的通知请求中缺少了两个属性。因此,使用PushSharp github回购协议中给出的示例:

需要更新以添加缺少的属性:

push.QueueNotification(new GcmNotification().ForDeviceRegistrationId("DEVICE REGISTRATION ID HERE")
                      .WithJson(@"{""alert"":""This is the future"",""badge"":7,""sound"":""sound.caf"",""title"":""Status Bar title"",""message"":""Some text you want to display to the user""}"));
否则,如果您的应用程序恰好是使用Cordova开发的,并且它当前不在前台,那么将不会发生任何事情,请重复

他对PushPlugin的评论为我指明了正确的方向:

push.QueueNotification(new GcmNotification().ForDeviceRegistrationId("DEVICE REGISTRATION ID HERE")
                      .WithJson(@"{""alert"":""This is the future"",""badge"":7,""sound"":""sound.caf"",""title"":""Status Bar title"",""message"":""Some text you want to display to the user""}"));