我有ngCordova本地通知工作,如何让它为每个用户触发

I have ngCordova local notification working, how can i make it trigger for every user

本文关键字:用户 ngCordova 通知 工作 我有      更新时间:2023-09-26

我有一个带文本区域的ionicPopup,当用户输入文本时,保存在firebase中。在这个值的改变上,我能够在移动设备上触发ngCordova本地通知谁的用户已经输入了数据。我如何让这个值更改在每个登录用户的手机上触发相同的通知。

服务:

servicesModule.factory("Profile", ["$firebaseObject",
  function($firebaseObject) {
    return function(new_value) {
      var ref = new Firebase("https://feedback-system.firebaseio.com/Courses/" + 'newValue');
      var new_value_ref = ref.child(new_value);
      return $firebaseObject(new_value_ref);
    }
  }
]);

控制器:

var ionicApp = angular.module('localNotificationModule', ['ionic', 'ngCordova']);
ionicApp.controller('localNotificationCtrl', ['$scope', '$rootScope', '$ionicPlatform', '$cordovaLocalNotification', '$state', 'Profile', '$firebase', 'Firebase', function($scope, $rootScope, $ionicPlatform, $cordovaLocalNotification, $state, Profile, $firebase, Firebase){
        $scope.profile = Profile("physicsmarie");
        // calling $save() on the synchronized object syncs all data back to our Firebase database
        $scope.testNotification = function() {
          $scope.profile.$save().then(function() {
            scheduleDelayedNotification($scope.profile.name);
          }).catch(function(error) {
            alert('Error!');
          });
        };
function scheduleDelayedNotification(newValue) {
    $ionicPlatform.ready(function () {
            $cordovaLocalNotification.schedule({
                id: 1,
                title: 'New Notification',
                text: newValue,
                autoCancel: true
            }).then(function (result) {
                alert("Notification Set");
            });
    });
    };
}]);

使用可以正常工作

firebaseRef.on('value', function(){
    local notification scheduling
});

但有两个问题。

  1. 也在邮件发送方触发通知
  2. 当应用程序的状态为"后台"时,通知失败