iOS4 - Make App not run in background

You must Login before you can answer or comment on any questions.

Does anyone know of anyway to make the app not run in the background on iOS4 when built using SDK 4.0?

My App is not really designed to run in the background, and if someone doesn't finish the task when they close the app it causes problems.

So I would like the app to "close" when the home button is pressed, so when the user opens the app again it starts up fresh.

Does anyone know how to do this?

Thanks

14 Answers

Andy,

Go to your info.plist in the build folder and edit it with a text editor and add this.

<key>UIApplicationExitsOnSuspend</key>
<true/>

Adding UIApplicationExitsOnSuspend AND copying the info.plist file to the project root is the solution.

— answered 4 years ago by Andrew Gray
answer permalink
2 Comments
  • by project root do you mean the same level as the .xcodeproj file? or somewhere else? THanks!

    — commented 4 years ago by karlo kilayko

  • See Tamas Daniel's answer which is the right approach. It would seem that just editing the info.plist in build/iphone will not work as the changes are lost when you build/launch with Titanium.

    — commented 4 years ago by Jaime Fuhr

The project's root is the folder above the Resources one, the folder that has tiapp.xml file. There you should put your Info.plist file.

Simply copy the file found in

build/iphone
and add the key specified by Donovan
<key>UIApplicationExitsOnSuspend</key>
    <true/>
delete the folder
build/iphone/build
to force a full rebuild and you should be set.

PS. All the above folder path are relative to the root of the application.

— answered 4 years ago by Dan Tamas
answer permalink
3 Comments
  • Awesome! Thanks so much, Tamas! It's working. One thing I would add: I initially tried editing Info.plist with the property editor. It added the key properly, but the boolean was added as <string>true</string> and it did not work. I edited Info.plist by hand to set the bool to <true/> as indicated above and now it works! Thanks again!

    — commented 4 years ago by karlo kilayko

  • I guess I don't know how to use the Property Editor? I'm sure there's a way to specify the value as a boolean :)

    — commented 4 years ago by karlo kilayko

  • This did the trick for me. Thanks!

    — commented 3 years ago by Gavy Aggarwal

Martijn,

Thanks for that. I actually did get it to work. I had to add it into the info.plist as a boolean type.

&lt;key&gt;UIApplicationExitsOnSuspend&lt;/key&gt;
&lt;true/&gt;

Thanks again

This by text edit is working:

<key>UIApplicationExitsOnSuspend</key> <true/>

This by Xcode is not working:

<key>UIApplicationExitsOnSuspend</key> <string>true</string>

you supposedly can set UIApplicationExitsOnSuspend to true in the info.plist, and the app should exit.

Are there any other things to consider for this? I tried adding UIApplicationExitsOnSuspend to Info.plist and Info.plist.template (both in Xcode proj root - same level as .xcodeproj file in build/iphone/build) and it does not work. I feel like an idiot for not being able to get this to work. Thanks!

I can confirm the code mentioned above works.

When I tried it at first it didnt work. It could be because used a text editor to edit the info.plist. So maybe my text editor is not plist-friendly. Danno suggested to edit the file in XCode and add the key (boolean), and that works. I copied the info.plist now into my root directory in case I want to delete the build folder so I wont have to edit the file again.

This by text edit is working:

<key>UIApplicationExitsOnSuspend</key> <true/>

This by Xcode is not working:

<key>UIApplicationExitsOnSuspend</key> <string>true</string>

This by text edit is working:

<key>UIApplicationExitsOnSuspend</key>
    <true/>
This by Xcode is not working:
<key>UIApplicationExitsOnSuspend</key>
    <string>true</string>

— answered 4 years ago by Lawrence Cheuk
answer permalink
1 Comment
  • The trick is that the value is not a string, it needs to be a boolean. See Tamas' post below on this (and my related comments of idiocy ;)

    — commented 4 years ago by karlo kilayko

To get the mobile application in iphone to close when the home button is clicked instead of continuing to run in the background first build your project for iphone.

Next go into the iphone's build folder and copy the info.plist file

build/iphone/Info.plist
Paste this file in the root directory for the whole project (the folder above the Resources folder)

Edit the file with a text editor (not xcode) and add this xml code before the </dict> element

<key>UIApplicationExitsOnSuspend</key>
<true/>
Save and rebuild and now it will close the application instead of suspending it to the background.

is there anyway I can set this programatically? My App needs to run in the background optionally, for example, when it downloads file, I want it to be able to run in the background, and otherwise, I want it to exit.

thanks ahead

You can do it right in Xcode...for those in the future that needs help heres how:

Click on "Info.plist" under Resources folder in the Xcode. Should show all the Keys it contains. Right click anywhere on that and "Add Row" (usually I select the last row to insert a new row to the bottom) Type in UIApplicationExitsOnSuspend for the key then press ENTER. Then right click on the key you made and select "Boolean" from the "Value Type". It will give you a check box next to it and simply just mark it. For future reference, to delete a row just click on a row then hit DELETE or select a row and Edit -->Delete

Is this really working? I have tried this on three different Apps including a default bare bones build and changing the plist file to include this has had no affect whatsoever. The Apps effectively suspend on pressing of the home button and resume on restart of the App. Im using Titanium 3.2 with 4.0SDK. I have tried using both True and YES for the boolean and still no joy. I urgently need to have my App fully close and not go into this suspend mode. Help!

Your Answer

Think you can help? Login to answer this question!