How to set an Alarm in iOS?

后端 未结 4 1651
长发绾君心
长发绾君心 2020-12-06 03:04

I know this question has asked many times on StackOverflow but i couldn\'t able to set alarm in my app because i am very new to iOS? I am following this tutorial to

4条回答
  •  青春惊慌失措
    2020-12-06 03:46

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

    2. 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: 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:

    Local notifications in iOS.

    tutorial you posted on how to do this.

提交回复
热议问题