如何告诉 iOS 我不希望应用程序停留在后台?
有没有办法告诉 iOS 我不希望我的应用程序停留在后台?换句话说,我可以告诉我的应用程序在进入后台时自行退出吗?
我在 UITbarController 的一个选项卡中使用 ABPeoplePickerNavigationController
。但是,每当到达 [ABMembersViewController applicationDidResume]
时,它都会崩溃并显示 EXC_BAD_ACCESS。
这里是堆栈跟踪:
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]
因此,为了解决这个问题,我认为如果我能够强制应用程序自行终止,我就可以完美地阻止程序执行这部分代码。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在您的 info.plist 中,将 UIApplicationExitsOnSuspend 设置为 yes
in your info.plist, set UIApplicationExitsOnSuspend to yes
尽管让应用程序退出而不是挂起可能会通过隐藏问题来解决问题,但您确实应该正确解决问题并确保您的应用程序可以应对挂起。
用户(在支持它的设备上)通常期望应用程序挂起,并且当他们出于某种原因切换到另一个应用程序时,可能会惊讶地发现您的应用程序似乎崩溃了(这就是他们看起来的样子)。
如果要回到之前的位置,需要付出更多的努力而不仅仅是重新启动应用程序,这将特别烦人。
继续......你知道这是有道理的......正确地做!
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!
如果不查看其余代码,就很难查明问题所在。通常,EXC_BAD_ACCESS 意味着您尝试向已释放的对象发送消息。您是否可以在 viewWillDisappear 或类似方法中释放某些内容,而不是在 viewWillAppear 中重新初始化它?
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?