1. GitHub source code address:
https://github.com/katzer/cordova-plugin-local-notifications
2. Parameter description:
https://github.com/katzer/cordova-plugin-local-notifications/wiki/04.-Scheduling
3. Event description:
https://github.com/katzer/cordova-plugin-local-notifications/wiki/09.-Events
4. Example of use:
1. Html code:
<ion-pane ng-app="notiTest" ng-controller="NotiCtrl"> <ion-header-bar class="bar-positive" align-title="center"> <h1 class="title">Simple Message Example</h1> </ion-header-bar> <ion-content> <ion-list> <ion-item ng-click="sendOne()"> send a single message </ion-item> <ion-item ng-click="sendTwo()"> send multiple messages </ion-item> <ion-item ng-click="sendThree()"> Repeat reminder </ion-item> <ion-item ng-click="sendFourth()"> method with parameters </ion-item> </ion-list> </ion-content> </ion-pane> <!-- Cordova reference, which is added to it when the application is built. --> <script src="cordova.js"></script> <script src="scripts/platformOverrides.js"></script> <script src="scripts/ionic/js/ionic.bundle.min.js"></script> <script src="scripts/index.js"></script>2. js code
1. Send a single message
cordova.plugins.notification.local.schedule({ id: 1, title: 'App Reminder', text: 'Apply new news, let's take a look', at: new Date().getTime(), badge: 2 }); //The new version uses add to replace schedule cordova.plugins.notification.local.add({ id: 1, title: 'App Reminder', text: 'Apply new news, let's take a look', at: new Date().getTime(), badge: 2, autoClear: true,//default value sound: 'res://platform_default',//default value icon: 'res://ic_popup_reminder', //default ongoing: false //default }); //Use Uri to define icon and sound failed, the reason has not been found cordova.plugins.notification.local.add({ id: 1, title: 'App reminder~~~1', text: 'Apply new news, let's take a look', at: new Date().getTime(), badge: 2, // Failed to use local audio sound: 'file://permission.mp3', //kick in //icon: 'ic_media_play', // Failed to use the body image icon: 'file://images/g.jpg', // Failed to use external network image //icon: "http://www.weilanliuxue.cn/Content/Images/Index2/h_index01.jpg", });
2. Send multiple messages
cordova.plugins.notification.local.schedule([{ id: 1, title: 'App reminder 1', text: 'Apply reminder content 1', at: new Date() }, { id: 2, title: 'App reminder 2', text: 'Apply reminder content 2', //The current time is delayed by 2 seconds at: new Date(new Date().getTime() + 1000 * 3) }]);
3. Send duplicate messages
cordova.plugins.notification.local.schedule({ title: 'Duplicate message title', text: 'Duplicate message content', at: new Date(), every: 'minute' });
4. Send a message with parameters
cordova.plugins.notification.local.schedule({ id: 1, title: 'with parameters', text: 'Content', firstAt: new Date(new Date().getTime() + 2 * 1000), every: 'minute', data: { meetingID: '1324', time: new Date() } });
5. Event monitoring
//shedule event fires every time it is called cordova.plugins.notification.local.on('schedule', function (notification) { alert('scheduled:' + notification.id); }); //Notify trigger event cordova.plugins.notification.local.on('trigger', function (notification) { //alert('triggered:' + notification.id); alert(JSON.stringify(notification)); }); //listen for click event cordova.plugins.notification.local.on('click', function (notification) { alert(JSON.stringify(notification)); document.getElementById('title').innerHTML = JSON.stringify(notification.data); });notification object content
Screenshot of the page
test operating system