Prevent application terminate

Discussion in 'iOS Programming' started by ruffurs, Aug 22, 2008.

  1. ruffurs macrumors newbie

    Aug 22, 2008

    I want to prevent application terminate when the user press Home Button. I want that application does nothing, whene the user press the HomeButton.

    I can output message in Console like this:

    - (void) applicationWillTerminate(UIApplication *)application {

    but i did not find how to cancel the application termination on iphone sdk. The method
    - (NSTerminateReply) applicationShouldTerminate:(NSApplication *)application {
    return NSTerminateCancel;

    of course, is not working on IPhone SDK.

    Is there any similar method on iphone sdk?

    [Edited:] This software will be used on IPod Touch. There will be a lot of users, and they are supposed to use only one application.

  2. robbieduncan Moderator emeritus


    Jul 24, 2002
    You cannot prevent the user terminating the application if they want to: it's their phone not yours.
  3. ruffurs thread starter macrumors newbie

    Aug 22, 2008
    Actually, that device (in this case, IPod Touch) will not be users, it will be mine.
  4. robbieduncan Moderator emeritus


    Jul 24, 2002
    Well, whilst I understand why you might want to force them into using only your app there is no way to do this directly with in the SDK.

    The best suggestion I have it is to subclass UIApplication and override the terminate method (see my posts here for a likely method to override) to not actually terminate the app.

    The issue would obviously be that unless you leave yourself some sort of backdoor you won't be able to terminate the app without force-rebooting the iPod either...
  5. Luke Redpath macrumors 6502a

    Nov 9, 2007
    Colchester, UK
    A few points:

    * As you might expect, such a function doesn't exist...
    * ...nor will it ever exist.
    * What you are trying to do is stupid
    * Even if such a function existed, you could not prevent people from force-quitting by holding down the home button...
    * ...or rebooting the device (because you can't auto-run apps).

    How about you trust your users? If this isn't an option, then an iPhone/iPod Touch is probably not a suitable solution for whatever you're trying to do.
  6. grimjim macrumors member

    May 24, 2003
    I think I can understand what you're trying to do: I often find myself signing for deliveries on Windows-Mobile-based devices that presumably only run the "sign-for-deliveries" app.

    The iPhone can't be closed down like this using the SDK, I'm afraid. If you need to deploy an app in such a manner that your users cannot quit it or switch to another, then I'm afraid that the iPhone is not going to be the right device for you.
  7. tskoti macrumors newbie

    Nov 5, 2008
    how to display alert when home button pressed while app is Running


    Please let me know, how to display an alert message when home button is pressed on the Iphone while the application is Running

    Thanks in Advanced,
  8. dejo Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    Even if you could, please don't.

Share This Page