且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 iOS 中设置闹钟?

更新时间:2023-01-29 19:14:28

  1. 首先在您的 xib,(或代码)上设置日期选择器模式:时间(默认为日期和时间)

  1. First on your xib, (or code) set the date picker mode: Time (Default is date & time)

系统假定firedate是当前日期,时间是用户选择的时间.这不是问题,因为您设置了重复间隔,因此它会起作用.我已经测试过了.

The system assumes that the firedate is the current date, and the time is the time the user have chosen. This is not a problem because you set a repeat interval so it will work. I have tested it.

UILocalNotification *localNotif = [[UILocalNotification alloc] init];
[localNotif setFireDate:datePicker.date];
[localNotif setRepeatInterval:NSDayCalendarUnit];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];

PS:***使用 NSDateComponents 类将秒数设置为 0,以便将闹钟设置为在您想.您可以检查:

PS: It would be a good idea to set the seconds to 0 using NSDateComponents class so as to set the alarm to ring at the first second of the minute you want. You can check the:

iOS 中的本地通知.

您发布的有关如何执行此操作的教程.

tutorial you posted on how to do this.