在ngcordova push ionicframework android中收到通知后,将用户重定向到特定页面

时间:2015-08-13 07:14:37

标签: android cordova push-notification ionic-framework phonegap-plugins

通过通知打开应用程序时,有一种方法可以将用户带到特定的页面或标签吗?

我发送推送,我的手机处于后台,用户访问应用程序,点击刚刚到达的通知。实际上,该应用程序打开已打开的页面,但我希望它打开通知选择的目标页面。

// ------------------------------ GCM NG-CORDOVA PUSH-----------------------------------
.run(function($ionicPlatform,ngFB,$state,$cordovaPush,$rootScope,$ionicScrollDelegate, $cordovaMedia) {
  $ionicPlatform.ready(function() {
var androidConfig = {
    "senderID": "XXXXXXXXXXX"
  };
 $cordovaPush.register(androidConfig).then(function(result) {
      // Success
      // alert(result);
    }, function(err) {
      // Error
      alert(err);
    });

    $rootScope.$on('$cordovaPush:notificationReceived', function(event, notification) {
      //alert(notification.event);
      switch(notification.event) {
        case 'registered':
          if (notification.regid.length > 0 ) {
          // alert('registration ID = ' + notification.regid);
          }
          break;

        case 'message':

        $ionicScrollDelegate.$getByHandle('chatScroll').scrollBottom();
          // this is the actual push notification. its format depends on the data model from the push server
          //alert('message = ' + notification.message + ' msgCount = ' + notification.msgcnt);
         alert(JSON.stringify(notification));
          if (notification.foreground)
            {
                // if the notification contains a soundname, play it.
               var soundfile = notification.soundname;
              // if the notification contains a soundname, play it.

              var media = $cordovaMedia.newMedia("/assets/www/"+ soundfile);
              media.play();
                alert(notification.payload.message);
            }
            else
            {
                window.location = '#/home';
                //$state.go('home');
            }
          break;

        case 'error':
          alert('GCM error = ' + notification.msg);
          break;

        default:
          alert('An unknown GCM event has occurred');
          break;
      }
    });



    // WARNING: dangerous to unregister (results in loss of tokenID)
   // $cordovaPush.unregister(options).then(function(result) {
      // Success!
    //}, function(err) {
      // Error
    //})


  });


})

请帮帮我。我在哪里做错了?

0 个答案:

没有答案