通知每天xcode



我想在每天的同一时间创建一个提醒。

示例代码如下:

- (IBAction)start:(id)sender {
    [defaults setBool:YES forKey:@"notificationIsActive"];
    [defaults synchronize];
    self.message.text=@"Напоминание включено";

    NSDate *date = [NSDate date];
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateComponents *components = [calendar components:(NSCalendarUnitHour | NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay) fromDate:date];
    components.calendar = calendar;
    components.hour = 7;
    components.minute = 37;
    date = components.date;
    if([date compare:[NSDate date]] < 0) {
        date = [date dateByAddingTimeInterval:60*60*24];
    }
    UILocalNotification* localNotification = [[UILocalNotification alloc] init];
    localNotification.alertBody = @"ТЕКСТ НАПОМИНАНИЯ";
    localNotification.timeZone = [NSTimeZone defaultTimeZone];
    localNotification.repeatInterval = NSCalendarUnitDay;//NSCalendarUnitMinute; //Repeating instructions here.
    localNotification.soundName = UILocalNotificationDefaultSoundName;
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}

试试这个

NSDate *date = [NSDate date]; 
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.fireDate = date;
localNotif.timeZone = [NSTimeZone defaultTimeZone];
localNotif.repeatInterval=NSCalendarUnitDay;
localNotif.alertBody = @"Daily Notification"; 
localNotif.userInfo=@{
                     };
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];

相关内容

  • 没有找到相关文章

最新更新