Tutorial: Fixing iOS4 "Multi-Tasking Attempt" Crashes

For iOS Developers:

Until Corona SDK officially supports multi-tasking, you need to include something that’s very important within your build.settings (plist) or you’ll end up annoying anyone who’s using iOS4.0 and above.

This is what you’ll add:

UIApplicationExitsOnSuspend = true
You can read the full explanation on iDeveloper:

–> http://ideveloper.kodingen.com/2010/fix-ios4-multi-tasking-crashes/

Special thanks to Eric Herrmann for helping me out with this one! [import]uid: 7849 topic_id: 2494 reply_id: 302494[/import]

That is a very good hint. Thank you! [import]uid: 5712 topic_id: 2494 reply_id: 7238[/import]

@MikeHart: I’m glad you found it useful! I think everyone needs to incorporate this. I haven’t seen it in any of the Corona documentation, but I’m not 100% sure it’s not there. Perhaps they plan on supporting multi-task events in the near future.

That would be cool, but not as cool as *in-app purchases* :slight_smile: [import]uid: 7849 topic_id: 2494 reply_id: 7239[/import]

@jonbeebe,

Thanks for the tip!

Is this any different than os.exit() and does it affect refreshes in the simulator like os.exit() does? Currently I just put a system event listener at the bottom of the main.lua file with a system.getInfo condition that does something like this:

local function onSystemEvent ( event )  
 local quitOnDeviceOnly = true  
 if quitOnDeviceOnly and system.getInfo("environment")=="device" then  
 if( event.type == "applicationExit" ) then  
 -- save some data  
  
 -- and then quit the game  
 os.exit()  
 end  
 end  
end  
Runtime:addEventListener( "system", onSystemEvent )  

I make sure the app is running on a device because os.exit() closes the simulator when you do a refresh. [import]uid: 8194 topic_id: 2494 reply_id: 7242[/import]

@dknell: I’m not sure if it’s the same, but I suggest you keep using what you’re using if you need things saved whenever the user exits out of the app, that is, if it prevents iOS4+ crashes when receiving ‘multi-task’ events.

In any other case, I’d definitely include the plist entry to avoid the crashes (trust me, they were pretty annoying). [import]uid: 7849 topic_id: 2494 reply_id: 7263[/import]

dknell,

thank you for the tip!!

os.exit() works with the Game Edition Beta (where the build.settings file crashes iOS4)

[import]uid: 6459 topic_id: 2494 reply_id: 7270[/import]

@jonbeebe

Great tip thanks and stops my game quitting on relaunch.

I solved it by creating a file named build.settings as follows:

[code]

settings =
{
orientation =
{
default = “portrait”
},

iphone =
{
plist =
{
UIApplicationExitsOnSuspend = true
},
},

}

[/code] [import]uid: 7863 topic_id: 2494 reply_id: 9888[/import]

Great tip jonbeebe. This fixed my own app. from crashing every other launch.

An app. could have a tough time making it through apple’s approval process if it crashes every other time it launches. Seems like this simple line is required and should be covered somewhere in the Corona Docs, but I couldn’t find it. [import]uid: 9422 topic_id: 2494 reply_id: 11373[/import]

This was extremely useful. Why is it buried in the off topic section?! This is very relevant and very much on topic for anyone developing an app and should be documented better (i.e. it should be in the samples).

On a similar note, the method for hiding the status bar in the samples, i.e. display.setStatusBar( display.HiddenStatusBar )is terrible. It will still show the bar for about a second after launch and then disappear.

It’s much better to use:
UIStatusBarHidden=true
in the build.settings file. That way the status bar will never be shown.
[import]uid: 10835 topic_id: 2494 reply_id: 11834[/import]

Another very useful pointer, I just noticed this. Thanks man. [import]uid: 12108 topic_id: 2494 reply_id: 23680[/import]

Why isn’t this solution working for me?

settings =  
{  
 orientation =  
 {  
 default = "landscapeRight",  
 supported =  
 {  
 "landscapeLeft", "landscapeRight"  
 },  
 },  
  
 iphone =  
 {  
 plist =  
 {  
 UIApplicationExitsOnSuspend = true,  
  
 UIStatusBarHidden = true,  
  
 UIAppFonts =   
 {  
 "pleasantlyplump.ttf",  
 "frfuhe.ttf"  
 },  
 },  
 },  
}  

In the simulator I can still see the status bar and on the device I can’t relaunch my app from the multitask menu? [import]uid: 30185 topic_id: 2494 reply_id: 24235[/import]

hm is this setting still needed? Perhaps a recent update to iOS fixed this crash? I put in that setting before, but as a test I just removed it and my app works fine. [import]uid: 12108 topic_id: 2494 reply_id: 25280[/import]

Nope, not needed now. You can handle suspend, start, resume events normally to support resume, or just do an os.exit() on suspend in corona if you dont want to bother.

I’m not sure what apple have to say if you dont support suspend resume tho. [import]uid: 8872 topic_id: 2494 reply_id: 25353[/import]

Thanks. For clarification, what exactly do you mean by “support suspend resume”? I mean, doesn’t iOS just automatically resume the game from the point where it was suspended? Also, what I’m doing right now is pausing the game on suspend; is that the sort of “support” you mean? [import]uid: 12108 topic_id: 2494 reply_id: 25355[/import]

if you receive a phone call you’ll get a applicationSuspend and then an exit. You’re supposed to save all your data, and the current state of the game and then exit.

When you get the applicationStart, you check for your suspend file, and if its present reload you’re game at the same point where u suspended.

iOS wont reload you’re game at the exact same point if its a real suspend (phone call or text message and u dont hit cancel on the popup).

If you don’t save state, when it comes back from resume - say after a phone call you’re game will just restart.

iOS only resumes your game where it left of if its a sleep - display timed out etc - in which case you’re game didnt actually exit.

Same on android BTW. [import]uid: 8872 topic_id: 2494 reply_id: 25358[/import]

My default orientation is landscaperight. After I inserted the

[lua]UIApplicationExitsOnSuspend = true [/lua]

line, the default orientation changed! What should I do??

My build.settings file: (although the file says landscaperight the default orientation is different)

[lua]settings = {
orientation =
{
default = “landscapeRight”,
},
iphone =
{
plist=
{

UIStatusBarHidden=true,
CFBundleIconFile = “Icon.png”,
CFBundleIconFiles = {
“Icon.png”,
“Icon@2x.png”,
“Icon-72.png”,
},
},
}
}
[import]uid: 44110 topic_id: 2494 reply_id: 75250[/import]

Where were you putting the line in? I just tested this using build 704 and worked fine;

[lua]settings = {
orientation =
{
default = “landscapeRight”,
},
iphone =
{
plist=
{

UIStatusBarHidden=true,
UIApplicationExitsOnSuspend = true,
CFBundleIconFile = “Icon.png”,
CFBundleIconFiles = {
“Icon.png”,
“Icon@2x.png”,
“Icon-72.png”,
},
},
}
}[/lua]

Peach :slight_smile: [import]uid: 52491 topic_id: 2494 reply_id: 75425[/import]

Thanks! It worked!
[import]uid: 44110 topic_id: 2494 reply_id: 75689[/import]

Not a problem - Merry Christmas!

Peach :slight_smile: [import]uid: 52491 topic_id: 2494 reply_id: 75741[/import]