- (void)applicationDidEnterBackground:(UIApplication *)application { NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar]; NSDateComponents *componentsForReferenceDate = [calendar components:(NSCalendarUnitDay | NSCalendarUnitYear | NSCalendarUnitMonth ) fromDate:[NSDate date]]; [componentsForReferenceDate setDay:27]; [componentsForReferenceDate setMonth:10]; [componentsForReferenceDate setYear:2016]; NSDate *referenceDate = [calendar dateFromComponents:componentsForReferenceDate]; // set components for time 7:00 am NSDateComponents *componentsForFireDate = [calendar components:(NSCalendarUnitYear | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond ) fromDate: referenceDate]; [componentsForFireDate setHour:10]; [componentsForFireDate setMinute:0]; [componentsForFireDate setSecond:0]; NSDate *fireDateOfNotification = [calendar dateFromComponents:componentsForFireDate]; // Create the notification UILocalNotification *notification = [[UILocalNotification alloc] init]; notification.fireDate = fireDateOfNotification; notification.timeZone = [NSTimeZone localTimeZone]; notification.alertBody = [NSString stringWithFormat: @"БЛАГОСЛОВИТЕ ПРОРОКА (с.а.в)"]; notification.alertAction = @"go back"; notification.userInfo= @{@"information": [NSString stringWithFormat:@"Some information"]}; notification.repeatInterval= NSCalendarUnitDay; notification.soundName = UILocalNotificationDefaultSoundName; [[UIApplication sharedApplication] scheduleLocalNotification:notification]; } |
[[UIApplication sharedApplication] cancelAllLocalNotifications];- Max Mikheyenko