How do I tell iOS that I do not want the app to stay in the background?

我的未来我决定 提交于 2019-12-20 07:14:13

问题


Is there a way to tell iOS that I do not want my app to stay in the background? In other word, can I tell my app to quit itself whenever getting into the background?

I am using ABPeoplePickerNavigationController in one of the tabs in my UITbarController. However, it crashes with a EXC_BAD_ACCESS whenever it reaches [ABMembersViewController applicationDidResume].

Here comes the stack trace:

0x00cc5994  <+0034>  mov    0x8(%eax),%eax
0x00cc5991  <+0031>  mov    0x8(%ebp),%eax
0x00cc598d  <+0027>  mov    %eax,0x4(%esp)
0x00cc5987  <+0021>  mov    0x4e082(%ebx),%eax
0x00cc597f  <+0013>  movl   $0x0,0x8(%esp)
0x00cc597e  <+0012>  pop    %ebx
ABCGetGroupCount
-[ABAccountsAndGroupDataSource hasMultipleAccountsOrGroups]
-[ABMembersViewController updateNavigationButtonsInSearchMode:animated:]
-[ABMembersViewController updateNavigationButtonsAnimated:]
-[ABMembersViewController applicationDidResume]

So, in order to work around it, I figure that if I am able to force the app to terminate itself, I can beautifully prevent the program to go through this part of the code.


回答1:


in your info.plist, set UIApplicationExitsOnSuspend to yes




回答2:


Although causing the app to exit rather than suspend may fix the problem by hiding it, you should really address the problem properly and ensure your app can cope with suspension.

Users (on devices that support it) generally expect apps to suspend and may be surprised that yours appears to crash (this is how it will look to them) when they switch away to another app for whatever reason.

This will be especially annoying if to get back to where they were before, takes more effort than just relaunching the app.

Go on ... you know it makes sense ... do it properly!




回答3:


Without seeing the rest of your code, it's hard to pinpoint the problem. Generally an EXC_BAD_ACCESS means you tried to send a message to a released object. Could you be releasing something in your viewWillDisappear or similar methods, and not re-initializing it in viewWillAppear?



来源:https://stackoverflow.com/questions/6127560/how-do-i-tell-ios-that-i-do-not-want-the-app-to-stay-in-the-background

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!