开发者

How do I play an alarm sound and present a custom view instead of just a notification?

开发者 https://www.devze.com 2023-03-12 20:58 出处:网络
I\'m working on an alarm clock application for iOS 4.x.The other alarm clock applications that I\'ve seen are able to present the user with something other than a local notification (i.e., a custom vi

I'm working on an alarm clock application for iOS 4.x. The other alarm clock applications that I've seen are able to present the user with something other than a local notification (i.e., a custom view) and are able to play a sound file. I've been looking into how that's done and have only found thi开发者_如何学Cs solution:

Play sound with screen turned off / don't let iPhone go to sleep

Is there another approach or is this the best practice?


When your app is not visible, you can't display anything. The silent sound workaround is a cool trick but when a user presses your home button, your app is not visible (and might get destroyed under certain conditions) -> therefore you can't display anything. So if you tell your user to use your alarm clock by firing it up and then press the sleep button it will work - you can display anything on your screen after the user unlocks the iphone again.
Needless to say that playing sound (even silent sound files) drains the battery so your user might be disappointed if he's not woken up because his iphone has run out of battery.
And yes, there is best practice: Local Notifications! Beginning with iOS 5 it will display your apps icon next to the notification...

0

精彩评论

暂无评论...
验证码 换一张
取 消