Commit 44c82937 by Sebastián Katzer

Cancel callbacks have not been fired after all notifications have been canceled on iOS

parent a3ff269d
...@@ -57,7 +57,7 @@ NSString *const kAPP_LOCALNOTIFICATION = @"APP_LOCALNOTIFICATION"; ...@@ -57,7 +57,7 @@ NSString *const kAPP_LOCALNOTIFICATION = @"APP_LOCALNOTIFICATION";
NSString* id = [notification.userInfo objectForKey:@"id"]; NSString* id = [notification.userInfo objectForKey:@"id"];
NSString* json = [notification.userInfo objectForKey:@"json"]; NSString* json = [notification.userInfo objectForKey:@"json"];
[self cancelNotificationWithId:id]; [self cancelNotificationWithId:id fireEvent:NO];
[self archiveNotification:notification]; [self archiveNotification:notification];
[self fireEvent:@"add" id:id json:json]; [self fireEvent:@"add" id:id json:json];
...@@ -77,10 +77,7 @@ NSString *const kAPP_LOCALNOTIFICATION = @"APP_LOCALNOTIFICATION"; ...@@ -77,10 +77,7 @@ NSString *const kAPP_LOCALNOTIFICATION = @"APP_LOCALNOTIFICATION";
NSArray* arguments = [command arguments]; NSArray* arguments = [command arguments];
NSString* id = [arguments objectAtIndex:0]; NSString* id = [arguments objectAtIndex:0];
UILocalNotification* notification = [self cancelNotificationWithId:id]; [self cancelNotificationWithId:id fireEvent:YES];
NSString* json = [notification.userInfo objectForKey:@"json"];
[self fireEvent:@"cancel" id:id json:json];
}]; }];
} }
...@@ -96,7 +93,7 @@ NSString *const kAPP_LOCALNOTIFICATION = @"APP_LOCALNOTIFICATION"; ...@@ -96,7 +93,7 @@ NSString *const kAPP_LOCALNOTIFICATION = @"APP_LOCALNOTIFICATION";
{ {
if ([key hasPrefix:kAPP_LOCALNOTIFICATION]) if ([key hasPrefix:kAPP_LOCALNOTIFICATION])
{ {
[[NSUserDefaults standardUserDefaults] removeObjectForKey:key]; [self cancelNotificationWithId:key fireEvent:YES];
} }
} }
...@@ -112,11 +109,14 @@ NSString *const kAPP_LOCALNOTIFICATION = @"APP_LOCALNOTIFICATION"; ...@@ -112,11 +109,14 @@ NSString *const kAPP_LOCALNOTIFICATION = @"APP_LOCALNOTIFICATION";
* *
* @param {NSString} id Die ID der Notification * @param {NSString} id Die ID der Notification
*/ */
- (UILocalNotification*) cancelNotificationWithId:(NSString*)id - (void) cancelNotificationWithId:(NSString*)id fireEvent:(BOOL)fireEvent
{ {
if (![self strIsNullOrEmpty:id]) if (![self strIsNullOrEmpty:id])
{ {
NSString* key = [kAPP_LOCALNOTIFICATION stringByAppendingString:id]; NSString* key = ([id hasPrefix:kAPP_LOCALNOTIFICATION])
? id
: [kAPP_LOCALNOTIFICATION stringByAppendingString:id];
NSData* data = [[NSUserDefaults standardUserDefaults] objectForKey:key]; NSData* data = [[NSUserDefaults standardUserDefaults] objectForKey:key];
if (data) if (data)
...@@ -126,11 +126,14 @@ NSString *const kAPP_LOCALNOTIFICATION = @"APP_LOCALNOTIFICATION"; ...@@ -126,11 +126,14 @@ NSString *const kAPP_LOCALNOTIFICATION = @"APP_LOCALNOTIFICATION";
[[NSUserDefaults standardUserDefaults] removeObjectForKey:key]; [[NSUserDefaults standardUserDefaults] removeObjectForKey:key];
[[UIApplication sharedApplication] cancelLocalNotification:notification]; [[UIApplication sharedApplication] cancelLocalNotification:notification];
return notification; if (fireEvent)
{
NSString* json = [notification.userInfo objectForKey:@"json"];
[self fireEvent:@"cancel" id:id json:json];
}
} }
} }
return NULL;
} }
/** /**
...@@ -211,7 +214,6 @@ NSString *const kAPP_LOCALNOTIFICATION = @"APP_LOCALNOTIFICATION"; ...@@ -211,7 +214,6 @@ NSString *const kAPP_LOCALNOTIFICATION = @"APP_LOCALNOTIFICATION";
notification.applicationIconBadgeNumber = badge; notification.applicationIconBadgeNumber = badge;
if (![self strIsNullOrEmpty:msg]) if (![self strIsNullOrEmpty:msg])
{ {
if (![self strIsNullOrEmpty:title]) if (![self strIsNullOrEmpty:title])
...@@ -257,7 +259,7 @@ NSString *const kAPP_LOCALNOTIFICATION = @"APP_LOCALNOTIFICATION"; ...@@ -257,7 +259,7 @@ NSString *const kAPP_LOCALNOTIFICATION = @"APP_LOCALNOTIFICATION";
if (autoCancel && !isActive) if (autoCancel && !isActive)
{ {
[self cancelNotificationWithId:id]; [self cancelNotificationWithId:id fireEvent:YES];
} }
[self fireEvent:event id:id json:json]; [self fireEvent:event id:id json:json];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment