********闹钟的特殊实现形式,无法解决的难题******
闹钟的原理我知道,无非就是使用Local Notification来实现,但是最近看到一个闹钟应用,觉得很新奇,大概说下它的表现:
1.如果把它从后台结束,那用的是普通的Notification形式出现。(也就是弹出通知)。
2.如果让它在后台运行(也就是按了home键,具体有没有在后台执行还是有疑问的,后面会说到),到了时间,它就一直在播放音乐以及震动。
疑问:
1.对于第一条,没有问题,本地通知就是这样的。
2.对于第二条,请问是如何实现的呢?按我的理解,app肯定是在后台偷偷的运行的,原理是神马呢?我通过查资料,找到如下文章,http://oleb.net/blog/2014/02/alarm-clock-apps-ios/ 里面的一段话是
Rise’s surprising solution is to opt out of iOS multitasking altogether. What was presumably intended by Apple as a temporary option for apps when multitasking was first introduced in iOS 4.0 is still available:
{If you do not want your app to run in the background at all, you can explicitly opt out of background by adding the UIApplicationExitsOnSuspend key (with the value YES) to your app’s Info.plist file. When an app opts out, it cycles between the not-running, inactive, and active states and never enters the background or suspended states.}
You can observe this behavior in Rise when you leave the app and immediately reopen it: it relaunches from scratch, showing the launch image again, rather than just wake up from the background.
需要把UIApplicationExitsOnSuspend 设置为YES,然后这里提到的 “when you leave the app and immediately reopen it: it relaunches from scratch, showing the launch image again, rather than just wake up from the background.” 是什么意思,如何实现呢?