Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
251 views
in Technique[技术] by (71.8m points)

uilocalnotification - How to set an Alarm in iOS?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
  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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...