Skip to content

PhoneGap plugin for providing native local notification system to JavaScript.

License

Notifications You must be signed in to change notification settings

wcwynn/phonegap-plugin-localNotifications

 
 

Repository files navigation

PLUGIN:

phonegap-plugin-localNotifications
version : 2.3
last update : 25/01/2013

CHANGELOG:


- Updated for cordova 2.3 (iOS only) - Updated for cordova 1.9 (iOS only)

DESCRIPTION :

PhoneGap plugin for providing native local notification system to JavaScript.

NOTE Notification queuing is iOS ONLY.

PROPS :

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

INSTALL (iOS):

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)

  1. 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.






EXAMPLE CODE



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);

About

PhoneGap plugin for providing native local notification system to JavaScript.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Objective-C 79.0%
  • JavaScript 19.3%
  • Other 1.7%