My app crash on exit after upgrade to sdk 4, the error is bad memory access.
I figured that if I put "exit(0)" in "applicationDidEnterBackground:(UIApplication *)application", the app would exit normally.
However, is this ok? This is my only "solution" to the problem so far.
NSZombie is not too helpful this time...
If there's a bad memory access issue, I think the best solution should be to find and fix the memory issue.
However, if you want to stick to the "prevent entering background" way, you should use the appropriate method : disable multitasking. It is described here.
If you do not want your application to remain in the background when it is quit, you can explicitly opt out of the background execution model by adding the UIApplicationExitsOnSuspend key to your application’s Info.plist file and setting its value to YES
Do not put exit(0) in applicationDidEnterBackground:(UIApplication *)application.
Instead, add a key to your Info.plist file to flag that you want the application to exit when it is suspended. For details look at Property List Options.
I find the source of the problem. The problem is that I need to perform all task that affect the interface or views on the main thread. Figuring out this also solved a multiply other bugs that give me headcase. It seems that iOS 4 is more restrictive on thread usage
Related
I added UIApplicationExitsOnSuspend to my Info.plist and set it to YES. The key completely exit my app when the home button is tapped.
But how about screen-lock ? or how can I detect screen lock event? There is no key named UIApplicationExitsOnScreenLock I want .
See the clever workaround in this answer. This seems to be the only way to do it but it is a hack, so changes to iOS could make it not work.
Quitting like that is not really appropriate. In your app delegate's -applicationWillResignActive:, just unauthenticate the user, or whatever it is you are trying to accomplish with a full re-start each time. I don't know what steel safe is, but it probably does not quit like that.
Or maybe check for the UIApplicationProtectedDataWillBecomeUnavailable notification? However, it's only sent on device lock if the user has a passcode enabled. If you use NSFileProtectionComplete on your "secret" files, close them when going inactive.
In my app I want the user to always see the rootViewController's view when the app is opened even if the app has not been killed completely.
One alternative I have considered is calling abort() in applicationWillResignActive: however this doesn't seem like a nice solution.
Any suggestions?
Set UIApplicationExitsOnSuspend in your Info.plist to true.
It appears that you can also set "Application does not run in background" to "true". This is found in the .plist.
i am developing a ebook reader and i am facing the following issue. if i close the app and reopen , then it opens exactly in the same state as it used to be before closing. I suspect this may lead to a lot memory leaks. Is this the right way for the app to function? and will this behavior cause any memory leaks?? can anyone help me with this... I dint know what title to put on top.. Please apologize me if the title was misleading.. thank you.
This is the expected behavior. After the introduction of iOS4, applications will keep their state between launches. Applications get terminated when the system is running low on memory, as the system terminates applications not recently used to free memory. This will not lead to memory leaks. For users running iOS3 pressing Home will terminate the application.
See Understanding an Application’s States and Transitions and Multitasking for more information.
right appropriate code in delegate file
-(void)applicationDidEnterBackground:(UIApplication *)application
{//exit(0);
}
if nothing works write exit(0) in this method.
You can add the BOOL key: "Application does not run in background" to your info.plist and set it to YES. Then your app should be terminated when you press the home button.
Hallo Everyone,
with the iOS 4, the iPhone is supporting Multitasking, what is very nice, but something I do not wish to support in my Application. I mean, when the user press the Home-button, I want my application to finish and not to enter in Background. With the iOS 4, when the User press the Home-button, the App calls the applicationDidEnterBackground: delegate's method to enter in Background and in order to "force" the Application to finish when the user press the Home button, I've done following implementation:
- (void)applicationDidEnterBackground:(UIApplication *)application {
//save everything...
exit(0);
}
PROBLEM: I've noticed, that exit(0) brings the Application immediately to finish, without calling deallocating methods like "dealloc", and I think that is not a good programming style. So I would like to ask you guys, how to bring the application to finish in a "nicer" way.
Thanks in advance.
What you actually want is not to exit the application (which is as mentioned not allowed), but tell the OS you would rather your application be killed rather than backgrounded.
There is an info.plist key for that, UIApplicationExitsOnSuspend. Set that in your info.plist to TRUE (checked) and then when your app enters the background it will be terminated.
That's two questions:
How to programmatically exit an iPhone app - duplicate
Proper way to exit iPhone application?
How to cause an iPhone app to not go to background in iOS4:
Add the UIApplicationExitsOnSuspend key to your info.plist and set its value to YES
http://developer.apple.com/iphone/library/documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW23
One answer above says "There is an info.plist key for that, UIApplicationExitsOnSuspend. Set that in your info.plist to TRUE (checked) and then when your app enters the background it will be terminated." with Xcode 4, the info.plist value is "Application does not run in background" of type Boolean, so setting this to YES will have the app exit when the user presses the "home" button.
You are not allowed to. I know from experience: got an app rejection from Apple because I've exited (that was two and a half years ago but I doubt they've changed their policy here). There's a "private" (i.e. not mentioned in header file) method "terminate" on UIApplication, IIRC. But Apple says you may not do that. Only thing you can do is to show a dialog, asking the user to press the home button. But in turn doesn't work if on a device with multitasking enabled... so I guess you really have to change your application in such a way that you can throw away your state on applicationDidEnterBackground and start afresh on application on applicationDidBecomeActive.
Everytime I quit the app in the simulator.
The console display this error message:
*** -[NSThread _nq:]: message sent to deallocated instance 0x6d770e0
Looks the app try to access an deallocated instance.
But I cannot find it anyhow, even using the instrument.
I can't find the line of code that cause the problem.
p.s. I have already tried any ways that I know to debug this problem. but no success yet.
I enabled NSZombie and use instrument to help me to find out the error. But the error report did not point to any of my own code. I have no idea why this happen.
Double click on your executable in the left pane in XCode, go to the arguments tab, add a new one named NSZombiesEnabled and set its value to YES. This will set all deallocated instance to an NSZombie and you'll be able to tell what type is being deallocated.
NOTE: THis must be turned off after or your app will never release memory!
Fixed, this problem is that I access interface objects not in the main thread. you can do so by [self performSelectorOnMainThread....].