如何告诉 iOS 我不希望应用程序停留在后台?

发布于 2024-11-09 09:43:32 字数 892 浏览 0 评论 0原文

有没有办法告诉 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

隐诗 2024-11-16 09:43:33

在您的 info.plist 中,将 UIApplicationExitsOnSuspend 设置为 yes

in your info.plist, set UIApplicationExitsOnSuspend to yes

月野兔 2024-11-16 09:43:33

尽管让应用程序退出而不是挂起可能会通过隐藏问题来解决问题,但您确实应该正确解决问题并确保您的应用程序可以应对挂起。

用户(在支持它的设备上)通常期望应用程序挂起,并且当他们出于某种原因切换到另一个应用程序时,可能会惊讶地发现您的应用程序似乎崩溃了(这就是他们看起来的样子)。

如果要回到之前的位置,需要付出更多的努力而不仅仅是重新启动应用程序,这将特别烦人。

继续......你知道这是有道理的......正确地做!

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!

琉璃梦幻 2024-11-16 09:43:33

如果不查看其余代码,就很难查明问题所在。通常,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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文