Files
phonegap-plugins/iPhone/LocalNotification/plugin/LocalNotification.m
cyerena 4afc891409 Update iPhone/LocalNotification/plugin/LocalNotification.m
To clear all notifications, just alter cancelAllNotifications fron LocalNotifications.m file adding:
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber: 1];
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];

before [[UIApplication sharedApplication] cancelAllLocalNotifications];

I hope, that solution can help.
2013-02-26 19:23:22 -06:00

76 lines
3.2 KiB
Objective-C
Executable File

//
// LocalNotification.m
// Phonegap LocalNotification Plugin
// Copyright (c) Greg Allen 2011 & 2012 Drew Dahlman
// MIT Licensed
#import "LocalNotification.h"
@implementation LocalNotification
- (void)addNotification:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options {
NSMutableDictionary *repeatDict = [[NSMutableDictionary alloc] init];
[repeatDict setObject:[NSNumber numberWithInt:NSDayCalendarUnit] forKey:@"daily"];
[repeatDict setObject:[NSNumber numberWithInt:NSWeekCalendarUnit] forKey:@"weekly"];
[repeatDict setObject:[NSNumber numberWithInt:NSMonthCalendarUnit] forKey:@"monthly"];
[repeatDict setObject:[NSNumber numberWithInt:NSYearCalendarUnit] forKey:@"yearly"];
[repeatDict setObject:[NSNumber numberWithInt:0] forKey:@""];
// notif settings
double timestamp = [[options objectForKey:@"date"] doubleValue];
NSString *msg = [options objectForKey:@"message"];
NSString *action = [options objectForKey:@"action"];
NSString *notificationId = [options objectForKey:@"id"];
NSString *sound = [options objectForKey:@"sound"];
NSString *bg = [options objectForKey:@"background"];
NSString *fg = [options objectForKey:@"foreground"];
NSString *repeat = [options objectForKey:@"repeat"];
NSInteger badge = [[options objectForKey:@"badge"] intValue];
bool hasAction = ([[options objectForKey:@"hasAction"] intValue] == 1)?YES:NO;
NSDate *date = [NSDate dateWithTimeIntervalSince1970:timestamp];
UILocalNotification *notif = [[UILocalNotification alloc] init];
notif.fireDate = date;
notif.hasAction = hasAction;
notif.timeZone = [NSTimeZone defaultTimeZone];
notif.repeatInterval = [[repeatDict objectForKey: repeat] intValue];
notif.alertBody = ([msg isEqualToString:@""])?nil:msg;
notif.alertAction = action;
notif.soundName = sound;
notif.applicationIconBadgeNumber = badge;
NSDictionary *userDict = [NSDictionary dictionaryWithObjectsAndKeys:notificationId,@"notificationId",bg,@"background",fg,@"foreground",nil];
notif.userInfo = userDict;
[[UIApplication sharedApplication] scheduleLocalNotification:notif];
NSLog(@"Notification Set: %@ (ID: %@, Badge: %i, sound: %@,background: %@, foreground: %@)", date, notificationId, badge, sound,bg,fg);
//[notif release];
}
- (void)cancelNotification:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options {
NSString *notificationId = [arguments objectAtIndex:0];
NSArray *notifications = [[UIApplication sharedApplication] scheduledLocalNotifications];
for (UILocalNotification *notification in notifications) {
NSString *notId = [notification.userInfo objectForKey:@"notificationId"];
if ([notificationId isEqualToString:notId]) {
NSLog(@"Notification Canceled: %@", notificationId);
[[UIApplication sharedApplication] cancelLocalNotification:notification];
}
}
}
- (void)cancelAllNotifications:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options {
NSLog(@"All Notifications cancelled");
[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 1];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];
[[UIApplication sharedApplication] cancelAllLocalNotifications];
}
@end