[英]Why does my iPhone App continue in the background?
I wrote my first iPhone App, and managed to get it into the App store. 我写了我的第一个iPhone App,并设法将其带入App Store。 I later discovered a bug that happens on a real device but not on my emulator.
后来我发现了一个在真实设备上发生的错误,但在我的模拟器上却没有。 I have committed a fix (changed plist to prevent app running in background), but I don't really understand why it happened.
我已提交了一个修复程序(更改了plist以防止应用程序在后台运行),但我并不十分了解为什么会发生这种情况。
My App allows users to record a sound-byte, however while they are recording they can use the iPhone home button to move the app to the background, and then it can keep recording forever if they don't restart the phone or the app does not crash. 我的应用程序允许用户录制声音字节,但是在录制过程中,他们可以使用iPhone的主页按钮将应用程序移至后台,然后,如果他们不重新启动手机或应用程序重启了,它可以永远进行录制不死机。
My impression from everything I have read, is that this should not happen as you have to ask for background audio specifically if you want to do this, but now it appears to me that you have to ask specifically to disable it. 从我所阅读的所有内容中,我的印象是,这不应该发生,因为如果您要这样做,则必须专门询问背景音频,但是现在看来,您必须专门要求将其禁用。
Could anyone explain this to me? 有人可以向我解释吗?
The iOS App lifecycle is described in Apple's iOS App Programming Guide . Apple的iOS应用程序编程指南中描述了iOS应用程序生命周期。
The App is given the opportunity to save data and otherwise stop things that don't need to be running, before being suspended. 该应用程序有机会保存数据,并在挂起之前停止不需要运行的操作。 You can request extra time doing this by using beginBackgroundTaskWithExpirationHandler: .
您可以使用beginBackgroundTaskWithExpirationHandler:来请求额外的时间。
If you want your app to stop doing its "normal thing" when it is put into the background then you need to detect the App state transition and stop it yourself. 如果您希望应用程序在后台运行时停止执行其“正常工作”,则需要检测应用程序状态转换并自行停止它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.