iPhone: How to set repeat daily/hourly local notification?

前端 未结 4 879
眼角桃花
眼角桃花 2020-12-16 08:45

I want to test add local notification. I want it repeat daily/hourly. How can I do that?

NSCalendar *calendar = [NSCalendar autoupdatingCurrentCalendar];

 /         


        
4条回答
  •  醉酒成梦
    2020-12-16 08:47

    UILocalNotification *localNotif = [[UILocalNotification alloc] init];
    if (localNotif == nil) return;
    
    NSDate *fireTime = [[NSDate date]   dateByAddingTimeInterval:900]; // 15 minutes
    
    localNotif.fireDate = fireTime;
    localNotif.alertBody = @"15 min reached";
    localNotif.repeatInterval=kCFCalendarUnitMinute;
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
    

提交回复
热议问题