0

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.

Winston Chen
  • 6,799
  • 12
  • 52
  • 81
  • Sounds like a crazy way to deal with a bug. Why not solve the problem instead of deliberately crashing the app? Your users will thank you (well, probably not, but they'll curse you if you don't). – nevan king May 25 '11 at 16:40
  • I would very much like to solve this actually. However like I said below, It's much like this problem: stackoverflow.com/questions/4813744/… It seems that apple has one more bug here. I could not find a single piece of my code involved in this case from the stack trace. It happens every time the program hits "-[ABMembersViewController applicationDidResume]". – Winston Chen May 26 '11 at 01:03
  • One other thought, but I can actually use another way to implement the part I need ABPeoplePickerNavigationController to come in. This might be a better way. Thanks man! – Winston Chen May 26 '11 at 01:20
  • I was thinking that a people picker is usually modal. You could dismiss it if the app is backgrounded. – nevan king May 26 '11 at 01:44
  • haha.. the thing is that I tried to reuse apple api to its extreme. So, I built one of the viewcontrollers by inheriting "ABPeoplePickerNavigationController". It is one of my major viewcontrollers directly under tabbarcontroller. I cannot dismiss it. – Winston Chen May 26 '11 at 06:57

3 Answers3

7

in your info.plist, set UIApplicationExitsOnSuspend to yes

Robot Woods
  • 5,677
  • 2
  • 21
  • 30
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!

Roger
  • 15,793
  • 4
  • 51
  • 73
  • The problem of this piece of code is that it is entirely apple's code. Resuming ABPeoplePickerNavigationController triggers the problem above. I set the break points everywhere in my code. But I could not see any of my code in the entire stack trace. It's much like this problem: http://stackoverflow.com/questions/4813744/weird-crash-in-abpeoplepicker It seems that apple has one more bug here. – Winston Chen May 25 '11 at 21:51
  • One other thought, but I can actually use another way to implement the part I need ABPeoplePickerNavigationController to come in. This might be a better way. Thanks man! – Winston Chen May 26 '11 at 01:20
0

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?

Joey Gibson
  • 7,104
  • 1
  • 20
  • 14