Reputation: 570
what is the best method to implement a alarm with my iPhone app? NSTimer, or DatePicker? help me with some code !
Upvotes: 1
Views: 9523
Reputation: 19469
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.
Upvotes: 6
Reputation: 16128
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!
Upvotes: 1