Commit d618a13f by Sebastián Katzer

Callbacks for non-repeating notifications were not called if they were not…

Callbacks for non-repeating notifications were not called if they were not created in the current app instance. Solves #87 partially.
parent 2691112e
...@@ -53,6 +53,7 @@ More informations can be found [here](https://build.phonegap.com/plugins/413). ...@@ -53,6 +53,7 @@ More informations can be found [here](https://build.phonegap.com/plugins/413).
#### Version 0.7.3 (not yet released) #### Version 0.7.3 (not yet released)
- [bugfix:] cancel callbacks have not been fired after all notifications have been canceled on iOS. - [bugfix:] cancel callbacks have not been fired after all notifications have been canceled on iOS.
- [change:] The `oncancel` callback will be called at last if `autoCancel` is set to true (iOS). - [change:] The `oncancel` callback will be called at last if `autoCancel` is set to true (iOS).
- [bugfix:] Callbacks for non-repeating notifications were not called if they were not created in the current app instance on iOS.
#### Version 0.7.2 (09.02.2014) #### Version 0.7.2 (09.02.2014)
- [enhancement:] Avoid blocking the main thread (on Android) **(dpogue)**. - [enhancement:] Avoid blocking the main thread (on Android) **(dpogue)**.
......
...@@ -141,6 +141,37 @@ NSString *const kAPP_LOCALNOTIFICATION = @"APP_LOCALNOTIFICATION"; ...@@ -141,6 +141,37 @@ NSString *const kAPP_LOCALNOTIFICATION = @"APP_LOCALNOTIFICATION";
} }
/** /**
* Entfernt alle Meldungen, die älter als x Sekunden sind.
*
* @param {float} seconds
*/
- (void) cancelAllNotificationsWhichAreOlderThen:(float)seconds
{
NSDictionary* entries = [[NSUserDefaults standardUserDefaults] dictionaryRepresentation];
NSDate* now = [NSDate date];
for (NSString* key in [entries allKeys])
{
if ([key hasPrefix:kAPP_LOCALNOTIFICATION])
{
NSData* data = [[NSUserDefaults standardUserDefaults] objectForKey:key];
if (data)
{
UILocalNotification* notification = [NSKeyedUnarchiver unarchiveObjectWithData:data];
NSTimeInterval fireDateDistance = [now timeIntervalSinceDate:notification.fireDate];
NSString* id = [notification.userInfo objectForKey:@"id"];
if (notification.repeatInterval == NSEraCalendarUnit && fireDateDistance > seconds) {
[self cancelNotificationWithId:id fireEvent:YES];
}
}
}
}
}
/**
* Archiviert die Meldungen, sodass sie später abgerufen werden kann. * Archiviert die Meldungen, sodass sie später abgerufen werden kann.
* *
* @param {UILocalNotification} notification * @param {UILocalNotification} notification
...@@ -179,7 +210,7 @@ NSString *const kAPP_LOCALNOTIFICATION = @"APP_LOCALNOTIFICATION"; ...@@ -179,7 +210,7 @@ NSString *const kAPP_LOCALNOTIFICATION = @"APP_LOCALNOTIFICATION";
[repeatDict setObject:[NSNumber numberWithInt:NSYearCalendarUnit] forKey:@"yearly"]; [repeatDict setObject:[NSNumber numberWithInt:NSYearCalendarUnit] forKey:@"yearly"];
#endif #endif
[repeatDict setObject:[NSNumber numberWithInt:0] forKey:@""]; [repeatDict setObject:[NSNumber numberWithInt:NSEraCalendarUnit] forKey:@""];
return repeatDict; return repeatDict;
} }
...@@ -278,6 +309,14 @@ NSString *const kAPP_LOCALNOTIFICATION = @"APP_LOCALNOTIFICATION"; ...@@ -278,6 +309,14 @@ NSString *const kAPP_LOCALNOTIFICATION = @"APP_LOCALNOTIFICATION";
} }
/** /**
* Löscht alle single-repeat Notifications, die älter als 5 Tage sind.
*/
- (void) onAppTerminate
{
[self cancelAllNotificationsWhichAreOlderThen:10];
}
/**
* Hilfsmethode gibt an, ob er String NULL oder Empty ist. * Hilfsmethode gibt an, ob er String NULL oder Empty ist.
*/ */
- (BOOL) strIsNullOrEmpty:(NSString*)str - (BOOL) strIsNullOrEmpty:(NSString*)str
......
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