TestsTested | ✓ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Dec 2014 |
Snooze UILocalNotification library.
You should put some code in AppDelegate
.
- (BOOL)application:(UIApplication *) application didFinishLaunchingWithOptions:(NSDictionary *) launchOptions {
UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
[[SnoozeLocalNotificationCenter center] cancelSnoozeForNotification:localNotif]
return YES;
}
- (void)applicationWillEnterForeground:(UIApplication *) application {
[[SnoozeLocalNotificationCenter center] cancelUnnecessarySnooze];
}
and schedule UILocalNotification
and snooze.
// Schedule 4 notification.
// fireDate -> 10min -> 30min -> 60min
NSArray *snoozeMinutes = @[@10, @30, @60];
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = [[NSDate date] dateByAddingTimeInterval:1000];
localNotification.alertBody = @"message";
[[SnoozeLocalNotificationCenter center] schedule:localNotification snoozeMinutes:snoozeMinutes];
@interface SnoozeLocalNotificationCenter : NSObject
+ (instancetype)center;
// schedule notification and snooze
- (void)schedule:(UILocalNotification *) snoozeLocalNotification snoozeMinutes:(NSArray *) snoozeMinutes;
// cancel all snooze notifications
- (void)cancelAllSnooze;
// cancel unnecessary notifications.
/* e.g) notificationA -> snoozeX -> snoozeY
* Notify notificationA, then user launch app.
* snoozeX and snoozeY are unnecessary notifications.
*/
- (void)cancelUnnecessarySnooze;
// cancel notification and snooze
- (void)cancelSnoozeForNotification:(UILocalNotification *) aNotification;
@end
SnoozeLocalNotification is available under the MIT license. See the LICENSE file for more info.