How to implement an alarm with iPhone SDK 4.0

2019-06-11 00:04发布

I have an idea for a pretty unusual alarm clock fir the iPhone. But as of now I have some thoughts on how to actually implement this. First off: forgetting about background services for now, how would I do the actual timer that fires the alarm etc? A separate thread? Or does the SDK include any nice alarm features I missed? Of cause I need to be as battery efficient as possible. But for now I do no background process.

Please advise me on this as it is a crucial concept of this app, if it will work or not.

2条回答
Luminary・发光体
2楼-- · 2019-06-11 00:33

You must create a UILocalNotification object and schedule it with scheduleLocalNotification, it is quite simple but there are strong limitations. You app may or may not be notified that the alarm occurred. When the alarm is presented, it will be in form of a AlertView. If the user taps "Close" you do not get a notification. If he taps "View Details", then you get the event didReceiveLocalNotification, your app moves to the foreground and can do whatever you want.

You can also register with iOS4 to receive updates on location change. The parsing of XML can be done but again there are limitations as to how much time you have to run methods in the background.

All information along with sample code can be found here: http://developer.apple.com/iphone/library/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html

查看更多
Explosion°爆炸
3楼-- · 2019-06-11 00:54

I would create a local notification. Compared to NSTimer, local notifications have the advantage that they work regardless of whether your app is running or not.

查看更多
登录 后发表回答