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

蹲街弑〆低调 提交于 2019-12-24 23:25:06

问题


I have an ionicPopup with textarea where when user enters text, saves in firebase. On this change of value im able to trigger ngCordova local notification on mobile who's user has entered data. How can i make this value change trigger same notification on every logged in user's mobile.

Service:

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);
    }
  }
]);

Controller:

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");
            });
    });
    };
}]);

回答1:


OK its working using,

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

with 2 problems though.

  1. Triggering notification on message senders side as well.
  2. Notification fails when app's state is 'background'.


来源:https://stackoverflow.com/questions/31109095/i-have-ngcordova-local-notification-working-how-can-i-make-it-trigger-for-every

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!