phonegap-plugin-localNotifications
version : 2.3
last update : 25/01/2013
- Updated for cordova 2.3 (iOS only) - Updated for cordova 1.9 (iOS only)
PhoneGap plugin for providing native local notification system to JavaScript.
NOTE Notification queuing is iOS ONLY.
Respect to Greg Allen 2011 - Copyright (c) MIT Licensed On which the (iOS & JS methods) plugin is based. Original can be found here https://github.com/purplecabbage/phonegap-plugins/tree/master/iPhone/LocalNotification
Project tree
project
/ www
-index.html
/ assets [store your app assets here]
/ phonegap
/ plugin
/ localNotification
/ localNotification.js
/ Classes
/ Plugins
/ LocalNotification
/ LocalNotification.h
/ LocalNotification.m
-project.xcodeproj
1 ) Arrange files to structure seen above.
2 ) Add to phonegap.plist in the plugins array;
Key : LocalNotification
Type : String
Value : LocalNotification
3 ) Add <script> tag to your index.html
<script type="text/javascript" charset="utf-8" src="phonegap/plugin/localNotification/localNotification.js"></script>
(assuming your index.html is setup like tree above)
- For observing and responding to notifications in JS, add code to your index.html
index.html
function onBodyLoad() {
document.addEventListener("receivedLocalNotification", onReceivedLocalNotification, false);
}
function onReceivedLocalNotification(event) {
var activeMessage;
if ( event.active === true ) {
activeMessage = ' while app was active';
} else {
activeMessage = ' while app was inactive';
}
var message = "Received local notificationId: " + event.notificationId + activeMessage;
console.log(message);
navigator.notification.alert(message);
}
4 ) Follow example code below.
Add a notification
localNotification.add(Int id, JSONObject options);
* NOTE* Adding a notification stops the notification and adds another.
{
seconds: 30,
message: "chaaaarrrliieeeee",
badge: 1
};
Queue a notification.
localNotification.queue(Int id, JSONObject options);
* NOTE* Queuing is currently iOS ONLY.
{
seconds: 30, message: "chaaaarrrliieeeee", badge: 1
};
Cancel a notification
localNotification.cancel(Int id);
Cancel all notifications
localNotification.cancelAll();
Set application badge value
localNotification.setApplicationBadge(Int value);
Get the application badge value
localNotification.getApplicationBadge(getSuccesFunction);
Handle application launch due to notification
localNotification.launch(standardLaunchFunction, launchDueToNotificationFunction);