ionic-team/ng-cordova

Getting Local Notifications working.

Open

#545 opened on Jan 6, 2015

View on GitHub
 (5 comments) (0 reactions) (0 assignees)JavaScript (3,493 stars) (1,072 forks)batch import
help wanted

Description

I'm struggling with Local Notifications.

I've pasted in the code from the docs into my controller and copy pasted the update from https://github.com/driftyco/ng-cordova/commit/b72ed84417f94342e8f3e485216bbe109c6eb003

into my ng-cordova.js file.

I don't get an error message, just nothing happens after the alert "set up notification" in either the ios emulator or on my phone when deploying with xcode.

Other ng cordova plugins work. Any help would be great. I've been chasing my tail with this for a while.

.controller('AboutCtrl', function($scope, $cordovaLocalNotification) {
  $scope.greatApp = function () {
    alert('set up notification');
    $cordovaLocalNotification.add({
      id: 'some_notification_id'
      // parameter documentation:
      // https://github.com/katzer/cordova-plugin-local-notifications#further-informations-1
    }).then(function () {
      alert('callback for adding background notification');
    });
  };

  $scope.cancelNotification = function () {
    $cordovaLocalNotification.cancel('some_notification_id').then(function () {
      alert('callback for cancellation background notification');
    });
  };

  $scope.cancelAllNotification = function () {
    $cordovaLocalNotification.cancelAll().then(function () {
      alert('callback for canceling all background notifications');
    });
  };

  $scope.checkIfIsScheduled = function () {
    $cordovaLocalNotification.isScheduled('some_notification_id').then(function (isScheduled) {
      alert(isScheduled);
    });
  };

  $scope.getNotificationIds = function () {
    $cordovaLocalNotification.getScheduledIds().then(function (scheduledIds) {
      alert(scheduledIds);
    });
  };

  $scope.checkIfIsTriggered = function () {
    $cordovaLocalNotification.isTriggered('some_notification_id').then(function (isTriggered) {
      alert(isTriggered);
    });
  };

  $scope.getTriggeredIds = function () {
    $cordovaLocalNotification.getTriggeredIds().then(function (triggeredIds) {
      alert(triggeredIds);
    });
  };

  $scope.notificationDefaults = $cordovaLocalNotification.getDefaults();

  $scope.setDefaultOptions = function () {
    $cordovaLocalNotification.setDefaults({ autoCancel: true });
  };

  // event callbacks events `onadd`, `ontrigger`, `onclick` and `oncancel`
  // can be assigned like this:
  $cordovaLocalNotification.onadd = function (id, state, json) {};
})

Contributor guide