A Cordova 2.3.0+ plugin to create local notifications on iOs by Olivier Lesnicki.
-
Place
LocalNotification.m
and LocalNotification.h in yourPlugins
folder -
Place
cordova.localNotification.js
in yourwww
folder -
Link your index page to
cordova.localNotification.js
-
In
config.xml
add the following within the<plugins>
tag<plugin name="LocalNotification" value="LocalNotification" />
In order to enable the notification listener we need to uncomment a number of lines in CDVPlugin.m
and `CDVPlugin.h
-
In
CordovaLib/Classes/CDVPlugin.m
uncomment the following line ininitWithWebView
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveLocalNotification:) name:CDVLocalNotification object:nil];
-
In
CordovaLib/Classes/CDVPlugin.m
uncomment the following lines at the end of the file- (void)didReceiveLocalNotification:(NSNotification *)notification {}
-
In
CordovaLib/Classes/CDVPlugin.h
uncomment the following line- (void)didReceiveLocalNotification:(NSNotification *)notification;
-
Place your
.caf sound in your App
Resourcesfolder (not the
www` folder)
// Schedules a local notification to be triggered after 5 seconds
window.addNotification({
fireDate : Math.round(new Date().getTime()/1000 + 5),
alertBody : "This is a local notification.",
repeatInterval : "daily",
soundName : "beep.caf",
badge : 0,
notificationId : 123,
callBack : function(notificationId){
alert("Hello World! This alert was triggered by notification" + notificationId);
}
});
- Implement badges (currently property is ignored)
- JavaScript validation
- Different callback if the app was in the background