简体   繁体   English

为什么我的iPhone App在后台继续运行?

[英]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.

相关问题 iPhone应用程序允许继续播放背景音乐 - iphone app allow background music to continue to play 为什么我的iPhone应用程序终止后仍未收到后台提取事件? - Why does my iphone app not receive background fetch events after being terminated? iPhone应用程序-为什么我的iPhone应用程序没有圆角? - Iphone app - Why does my iPhone app not get rounded corners? iPhone:为什么当应用程序进入后台时,applicationMusicPlayer为什么会退出播放? - iPhone: Why does applicationMusicPlayer quit playing when app enters background? 为什么iPhone应用程序更新会破坏我的应用程序? - Why does iPhone app update break my app? 为什么未通过xcode启动我的iPhone应用程序时崩溃 - Why does my iPhone app crash when not launched by xcode 为什么我的应用图标没有出现在 iPhone 的一个系统功能中? - Why does my app icon not appear in one system function on iphone? 为什么我的iPhone应用程序重新打开后会崩溃? - Why does my iPhone app crash after re-opening it? 为什么performSelector:afterDelay:立即在我的iPhone应用程序中起作用? - why does performSelector: afterDelay: act immediately in my iPhone app? 为什么我的iPhone应用程序图标有垂直线? - Why does my iPhone app icon have vertical lines?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM