|
@@ -118,8 +118,8 @@ NSString *const kAPP_LOCALNOTIFICATION = @"APP_LOCALNOTIFICATION";
|
|
|
if (![self strIsNullOrEmpty:id])
|
|
if (![self strIsNullOrEmpty:id])
|
|
|
{
|
|
{
|
|
|
NSString* key = ([id hasPrefix:kAPP_LOCALNOTIFICATION])
|
|
NSString* key = ([id hasPrefix:kAPP_LOCALNOTIFICATION])
|
|
|
- ? id
|
|
|
|
|
- : [kAPP_LOCALNOTIFICATION stringByAppendingString:id];
|
|
|
|
|
|
|
+ ? id
|
|
|
|
|
+ : [kAPP_LOCALNOTIFICATION stringByAppendingString:id];
|
|
|
|
|
|
|
|
NSData* data = [[NSUserDefaults standardUserDefaults] objectForKey:key];
|
|
NSData* data = [[NSUserDefaults standardUserDefaults] objectForKey:key];
|
|
|
|
|
|
|
@@ -140,6 +140,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.
|
|
|
*
|
|
*
|
|
@@ -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;
|
|
|
}
|
|
}
|
|
@@ -277,6 +308,14 @@ NSString *const kAPP_LOCALNOTIFICATION = @"APP_LOCALNOTIFICATION";
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveLocalNotification:) name:CDVLocalNotification object:nil];
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveLocalNotification:) name:CDVLocalNotification object:nil];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * 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.
|
|
|
*/
|
|
*/
|