How to set an Alarm in iOS?

vinothp picture vinothp · Aug 7, 2012 · Viewed 16.6k times · Source

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 set an alarm:

Setting a reminder using UILocalNotification in iOS.

However, it doesn't seems to be working for me.

I am in need to set alarm daily lets say 5.00 PM daily. I can't use date picker for choosing the time.

Answer

gsach picture gsach · Aug 7, 2012
  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.