Ionic 1: Local Notification
by Mubasshir Pawle
JavaScript
$scope.addSchedule = function(prescription_id, schedule_notification_id, title, description, date, vibration, tone, time_in_milli, originalChild) {
if (typeof cordova === 'undefined') {
return;
}
//checking if we have permission
cordova.plugins.notification.local.hasPermission(function(granted) {
$scope.localNotificationPermission = granted;
if (granted) {
time_in_milli = time_in_milli || date.getTime();
var id = parseInt(time_in_milli / 1000);
originalChild = originalChild || date.getTime();
var options = {
id: id,
title: title,
text: description,
at: date,
badge: 1,
data: {
localnotification_schedule_id: id,
child: originalChild,
prescription_id: prescription_id,
schedule_notification_id: schedule_notification_id
},
sound: 'file://tunes/' + $scope.user.setting.alertTone.replace('mp3', 'caf')
};
if (ionic.Platform.isAndroid()) {
options = angular.extend(options, {
ongoing: true,
headsup: true,
led: "00FF00",
style: "bigtextview",
vibration: vibration,
sound: 'file://tunes/' + $scope.user.setting.alertTone
});
// delete options.badge;
}
if (!tone) {
delete options.sound;
}
// check if notificationId already exists
cordova.plugins.notification.local.isPresent(id, function(present) {
if (present) { // append data to description
// get data of notification already exists
cordova.plugins.notification.local.get(id, function(notification) {
//checking if
cordova.plugins.notification.local.update({
id: id,
title: notification.title + ', ' + title,
text: notification.text + ', ' + description
});
}, function(error) {
console.log(error);
});
} else...