Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

iOS4 - Make App not run in background

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

— asked July 2nd 2010 by donovan lewis
  • app
  • close
  • ios4
0 Comments

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/>
    
    — answered July 5th 2010 by donovan lewis
    permalink
    0 Comments
  • Adding UIApplicationExitsOnSuspend AND copying the info.plist file to the project root is the solution.

    — answered July 5th 2010 by Andrew Gray
    permalink
    2 Comments
    • by project root do you mean the same level as the .xcodeproj file? or somewhere else? THanks!

      — commented July 22nd 2010 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 January 13th 2011 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 July 22nd 2010 by Dan Tamas
    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 July 22nd 2010 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 July 22nd 2010 by karlo kilayko
    • This did the trick for me. Thanks!

      — commented July 28th 2011 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.

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

    Thanks again

    — answered July 2nd 2010 by donovan lewis
    permalink
    0 Comments
  • This by text edit is working:

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

    This by Xcode is not working:

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

    — answered August 24th 2010 by Lawrence Cheuk
    permalink
    0 Comments
  • you supposedly can set UIApplicationExitsOnSuspend to true in the info.plist, and the app should exit.

    — answered July 2nd 2010 by Martijn Pannevis
    permalink
    0 Comments
  • 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!

    — answered July 22nd 2010 by karlo kilayko
    permalink
    0 Comments
  • 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.

    — answered August 2nd 2010 by Felipe Apostol
    permalink
    0 Comments
  • This by text edit is working:

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

    This by Xcode is not working:

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

    — answered August 24th 2010 by Lawrence Cheuk
    permalink
    0 Comments
  • This by text edit is working:

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

    This by Xcode is not working:

    <key>UIApplicationExitsOnSuspend</key>
        <string>true</string>
    
    — answered August 24th 2010 by Lawrence Cheuk
    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 August 24th 2010 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.

    — answered October 25th 2010 by Audra M. King
    permalink
    0 Comments
  • 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

    — answered November 15th 2010 by jason hu
    permalink
    0 Comments
  • 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

    — answered November 30th 2010 by dMd dMd
    permalink
    0 Comments
  • 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!

    — answered July 4th 2010 by Andrew Gray
    permalink
    1 Comment
    • did you add it inside xcode?

      — commented July 5th 2010 by danno watts
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.