Skip to content

Instantly share code, notes, and snippets.

@ktakayama
Last active January 29, 2018 14:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ktakayama/5fa9ade27eb55e6f393b74db49a1969a to your computer and use it in GitHub Desktop.
Save ktakayama/5fa9ade27eb55e6f393b74db49a1969a to your computer and use it in GitHub Desktop.
- (void) method {
UIApplication *application = [UIApplication sharedApplication];
[application cancelAllLocalNotifications];
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
NSDate *today = [NSDate date];
NSUInteger i = 0;
NSUInteger mx = 2;
for(i = 0 ; i <= mx ; i++) {
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.fireDate = [today dateByAddingTimeInterval:(i+1)];
localNotif.timeZone = [NSTimeZone localTimeZone];
if( i == mx ) {
localNotif.applicationIconBadgeNumber = -1;
} else {
localNotif.applicationIconBadgeNumber = mx - i;
}
[application scheduleLocalNotification:localNotif];
/*
UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
if( i == mx ) {
content.badge = @(-1);
} else {
content.badge = @(mx - i);
}
UNTimeIntervalNotificationTrigger *trigger =
[UNTimeIntervalNotificationTrigger triggerWithTimeInterval:(i+1) repeats:NO];
NSString *type = [NSString stringWithFormat:@"alarm%@", @(i)];
UNNotificationRequest* request =
[UNNotificationRequest requestWithIdentifier:type content:content trigger:trigger];
[center addNotificationRequest:request withCompletionHandler:NULL];
*/
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment