Skip to content

Phonegap plugin to create & cancel native, local notifications

License

Notifications You must be signed in to change notification settings

whiteoctober/LocalNotifications

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LocalNotifications

This plugin hooks into the Local Notification API, allowing you to create & cancel notifications for users of your app.

The goals of this project are to unify iOS & Android implementations and support the Cordova Plugin spec, so that it works with Pluginstall.

Great post explaining how to use pluginstall.

Android

  1. Install via pluginstall
  2. Include LocalNotification.js in index.html
  3. Modify AlarmReceiver.java to import to your R class (modify the package name)
  4. Start using window.plugins.localnotification

iOS

  1. Install via pluginstall

  2. Include LocalNotification.js in index.html

  3. Add the following code to AppDelegate.m

     - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification 
     {
         UIApplicationState state = [application applicationState];
         if (state == UIApplicationStateActive) {
             // WAS RUNNING
             NSLog(@"I was currently active");
    
             NSString *notCB = [notification.userInfo objectForKey:@"foreground"];
             NSString *notID = [notification.userInfo objectForKey:@"notificationId"];
    
             NSString * jsCallBack = [NSString 
                                     stringWithFormat:@"%@(%@)", notCB,notID];  
    
    
             [self.viewController.webView  stringByEvaluatingJavaScriptFromString:jsCallBack];
    
             application.applicationIconBadgeNumber = 0;
         }
         else {
             // WAS IN BG
             NSLog(@"I was in the background");
    
             NSString *notCB = [notification.userInfo objectForKey:@"background"];
             NSString *notID = [notification.userInfo objectForKey:@"notificationId"];
    
             NSString * jsCallBack = [NSString 
                                     stringWithFormat:@"%@(%@)", notCB,notID]; 
             [self.viewController.webView stringByEvaluatingJavaScriptFromString:jsCallBack];         
    
             application.applicationIconBadgeNumber = 0;
         }                 
     }
    
  4. Start using window.plugins.localnotification

Information

Originally forked from https://github.com/phonegap/phonegap-plugins

Repo format based on http://shazronatadobe.wordpress.com/2012/11/07/cordova-plugins-put-them-in-your-own-repo-2/

Credits

All the hard work on these plugins was done by Drew & Daniel.
I've merely collected them here and attempted to unify them.

About

Phonegap plugin to create & cancel native, local notifications

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 72.8%
  • Objective-C 15.1%
  • JavaScript 12.1%