what is the best method to implement a alarm with my iPhone app? NSTimer, or DatePicker? help me with some code !
-
I think you will need to use DatePicker. Also you can use UILocalNotifications which could be a great help. You can pick Alarm date from DatePicker and then set it as `firedate` for your UILocalNotification. ! – Parth Bhatt Apr 11 '12 at 05:25
-
If you have another question, please post it separately rather than editing it into this one -- no one is likely to see it. – jscs Apr 11 '12 at 16:58
2 Answers
I think you will need to use DatePicker.
Also you can use UILocalNotifications, which could be a great help.
You can pick Alarm date from DatePicker and then set it as fireDate
for your UILocalNotification.
For more information you may want to refer to UIDatePicker Class Reference and UILocalNotification Class Reference
EDIT:
Refer to this post and answer of Ole Begemann under it:
How to implement an alarm with iPhone SDK 4.0
Also refer to this sample code, I have not checked it personally but may be it could help you:
EDIT-2: Solution about playing custom sounds in Local notifications
Add any file in your iPhone app's Resources and then use the below code:
Let us suppose that notification
is an object of type UILocalNotification
.
notification.soundName = @"sound.caf";
If this doesn't work initially then you may refer to this post and there in refer to answer of Noah Witherspoon. That tells us to use sound file of the correct format (i.e. either Linear PCM or IMA4).
Choose custom sound for local notifications
Hope this helps.
Let me know if you need more help.

- 1
- 1

- 19,381
- 28
- 133
- 216
-
-
yes, as you said i have chosen the UILocalNotifications. my code is here, see my edited question – Neeraj Neeru Apr 11 '12 at 06:34
-
@ParthBhatt: Hi, Need quick answer so... Will `UILocalNotifications` fire even if app is closed ? not in background ? – Maulik Feb 12 '13 at 13:39
you should investigate a bit before asking straight away, [avoid downvotes i had a few ;)]
video tutorial building an iOS alarm
so you need basically a time keeping functionality = NSTimer
*Any time you are implementing a timer, the best option is always to record your start time. Then, whenever you update your interface, simply take the difference of the current time and your start time.
and the date picker is for setting the time with a picker... so
when the actual system time == your picker selected time :: sound alarm!

- 15,428
- 33
- 118
- 216
-
thank you for your feedback, actually the problem is the way i asked the question. i already done a research about alarm on iPhone and found two methods are basically using, NSTimer and LocalNotifier , and am bit confused about what is the best method? – Neeraj Neeru Apr 11 '12 at 06:33