iOS中的闹钟应用程序 [英] Alarm clock app in iOS

查看:112
本文介绍了iOS中的闹钟应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须为iPhone创建一个闹钟应用程序,用户可以在其中设置闹钟时间和声音。
这样做,我使用了UILocalNotification来引发警报。

I have to create an alarm clock app for the iPhone in which user can set alarm time and sound. In doing so, I have used UILocalNotification to set off the alarm.

现在,在UILocalNotification中,我们首先获得带有关闭和查看选项的通知警报。如果用户点击查看,那么我的代理会收到应用程序:didReceiveLocalNotification:消息并播放警报声。

Now, in UILocalNotification, first we get Notification Alert with option "Close" and "View". If the user taps on "View", then my delegate receives the application:didReceiveLocalNotification: message and the alarm sound plays.

但是在系统原生警报应用中,我们看不到通知警报;它只是直接播放警报声。如何让我的应用程序使用此行为?

But in the system-native alarm app, we don't see a notification alert; it just directly plays the alarm sound. How can I have my app use this behavior?

推荐答案

我同意David的观点。 iOS内置报警应用程序从Apple获得特殊处理,在后台声音> 30秒。它似乎使用一些私有API使它在较长时间内发出声音,即使它在后台或关闭时也是如此。这不适用于Apple以外的其他应用程序,所以甚至不要尝试与它竞争。如果您购买App Store中的所有闹钟应用程序(又名:Apple批准)并逐一尝试,您会发现它们在警报的最重要功能中缺少内置警报应用程序:即Sounding在很长一段时间内,应用程序处于任何状态(活动,背景或关闭)

I agree with David. iOS built-in alarm app gets a special treatment from Apple to sound > 30 seconds while in the background. It seems to be using some private API to make it sound for a longer time even when it is in the background or closed. This is not available to other apps built outside of Apple, so don't even try to compete with it. If you buy all Alarm clock apps in the App Store (aka: approved by Apple) and try them one by one, you will see that they lack behind the built-in alarm app in the most important function of an alarm: i.e. "Sounding for a long period, in any state the app is in (active, background, or closed)"

模拟背景警报的最佳选择是利用UILocalNotification持续30秒。如果你真的想要唤醒沉重的睡眠者,计划在相隔六十秒的时间内发出五个这样的通知,或希望他们在第五次通知结束前醒来。

Your best bet to simulate a background alarm is to make use of UILocalNotification for 30 seconds. If you really want to wake up your heavy sleeper, schedule to fire up five of these notifications sixty seconds apart or something like that, in the hopes they will wake up before the 5th notification ends.

请注意,使用这种方法,你的用户在他们醒来时会错过警报会在他们的屏幕上弹出5个弹出窗口(如果他们在其中一个警报弹出窗口中醒来,会少一些),所以他们会花掉他们的第一个他们早上关闭那些弹出窗口的秒数 - 不是最好的用户体验。

Notice that with this method, your user who misses the alarm will get 5 popups on their screen when they wake up (less if they wake up during one of the alarm popups), so they'll be spending their first seconds of their morning closing those popups - not the greatest user experience.

结论:闹钟应用程序仅适用于前台使用。适用于任何州的最佳闹钟应用程序是由Apple制作的内置时钟应用程序。

Conclusion: Alarm Clock apps are good for foreground use only. Best Alarm app out there that will work in any state is the built-in Clock app made by Apple.

这篇关于iOS中的闹钟应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆