Cordova Plug-in local Notification (native notification)

Source: Internet
Author: User



Original link: http://www.ncloud.hk/%E6%8A%80%E6%9C%AF%E5%88%86%E4%BA%AB/cordova-pluginslocal-notification/



The basic purpose of a local notification is to enable the application to inform the user that it provides them with some information, such as when the application is not running in the foreground, notifies the user of a message or an upcoming appointment. Local notifications are mostly time-based, and if triggered, they are displayed and presented to the user in the notification hub.



The local notification plugin can be Schedule () Schedule One or more local notifications at once, which can be triggered immediately or at some point in time. When scheduling multiple notifications, be aware that you want to use an array of schedule ([]) to include all the notifications.



A numeric ID is required for each local notification, and no default is set to 0 , but calling local notifications will replace the same ID in the earlier one.



Here are some properties:



650) this.width=650; "Src=" http://www.ncloud.hk/media/7210/%E5%B1%8F%E5%B9%95%E5%BF%AB%E7%85% a7-2016-03-03-31912-pm.png?width=500&height=339.36915887850466 "style=" border:0px;vertical-align:middle; width:500px;height:339.369px; "/>





First install the plugin by executing the following command:


Cordova Plugin Add Https://github.com/katzer/cordova-plugin-local-notifications.git


An example of a notification:


$scope.scheduleSingleNotification = function () {
Cordova.plugins.notification.local.schedule({
   Id: 1,
   Title: ‘App reminder’,
   Text: ‘There are new news for the app, come check it out’,
   At: new Date(new Date().getTime() + 5 * 60 * 1000)
   });
};


Examples of multiple notifications:


$scope.scheduleMutipleNotification = function () {
Cordova.plugins.notification.local.schedule({
   Id: 1,
   Title: ‘App Alert 1’,
   Text: ‘There are new news for the app, come check it out’,
   At: new Date(new Date().getTime() + 5 * 60 * 1000)
   },{
Id: 2,
   Title: ‘App Alert 2’,
   Text: ‘There are new news for the app, check it out’,
   At: new Date(new Date().getTime() + 10 * 60 * 1000)
});
};


Delay Reminders:


$scope.scheduleDelayedNotification = function () {
var now             =newDate().getTime(),
    _5_sec_from_now =newDate(now +5*1000);
 
cordova.plugins.notification.local.schedule({
    text:"Delayed Notification",
    at: _5_sec_from_now,
    sound:null
});
};


Repeat reminder:


$scope.scheduleRepeatedlyNotification = function () {
cordova.plugins.notification.local.schedule({
    text:"Repeatedly Notification",
    firstAt: monday,
    every:"day",
    icon:"file://img/logo.png"
}, callback);
}


There are two common types of events:



The schedule event will trigger each local notification when you call schedule (), and the trigger event will trigger the notification only if it reaches its trigger event.



Schedule Event:


cordova.plugins.notification.local.on("schedule", function(notification) {
    alert("scheduled: "+ notification.id);
});


Trigger Event:


cordova.plugins.notification.local.on("trigger", function(notification) {
    alert("triggered: "+ notification.id);
});





Cordova Plug-in local Notification (native notification)


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.