Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Exit Application

moo_gamermoo_gamer Posts: 45Registered Users
Hi! All,

I want to add a button to exit from my application. Which button I should call then? Thanks in advance.
Post edited by moo_gamer on
· ·

Replies

  • ayasinayasin Posts: 239Registered Users
    edited November 2008
    Just out of curiosity, what's wrong with exiting via the home button?
    <font size="2"><a href="http://www.pdascent.com/Site/iNeedStuff.html" target="_blank">iNeedStuff shopping assistant</a> - get in, get out, get on with your life</font>
    · ·
  • moo_gamermoo_gamer Posts: 45Registered Users
    edited November 2008
    :D, no wrong. But I want it.
    · ·
  • ayasinayasin Posts: 239Registered Users
    edited November 2008
    [[UIApplication sharedApplication] terminateWithSuccess];
    
    <font size="2"><a href="http://www.pdascent.com/Site/iNeedStuff.html" target="_blank">iNeedStuff shopping assistant</a> - get in, get out, get on with your life</font>
    · ·
  • RickMaddyRickMaddy Posts: 2,122New Users
    edited November 2008
    I have no idea if this will actually work but you could try stopping the main run loop.

    Look at the CFRunLoop reference. I'm guessing that stopping the main run loop will cause your app to stop cleanly.

    You could just call 'exit' but this won't be a clean shutdown of your app.
    · ·
  • RickMaddyRickMaddy Posts: 2,122New Users
    edited November 2008
    The docs don't show that method. If that works then that is certainly better than my guess.
    · ·
  • ayasinayasin Posts: 239Registered Users
    edited November 2008
    RickMaddy wrote: »
    The docs don't show that method. If that works then that is certainly better than my guess.

    It's undocumented, but it should work. If you don't use class-dump to get the full headers for UIKit the compiler will complain that "UIApplication may not respond to this selector" but it should work. Disclaimer: I've never tried this selector as I'm quite satisfied with the behavior of the home button ;).
    <font size="2"><a href="http://www.pdascent.com/Site/iNeedStuff.html" target="_blank">iNeedStuff shopping assistant</a> - get in, get out, get on with your life</font>
    · ·
  • lbendlinlbendlin Posts: 429Registered Users
    edited February 2009
    yes, it does work. To make the warning message go away use
    @interface UIApplication (extended)
    -(void) terminateWithSuccess;
    @end
    
    in the .h file.


    Now - is there a way to actually restart my app? ie terminate and start again?
    · ·
  • Jeremy1026Jeremy1026 Posts: 1,095Registered Users @ @ @ @
    edited February 2009
    I'm guessing no, because once your application is closed, you no longer have control over it. The best bet would be to try opening your app via the openURL method.
    <a href="http://www.1026dev.com/55555_contest" target="_blank">1026 Development's Bingo World Wide 55,555th Winner Contest</a><br />
    <a href="http://itunes.apple.com/us/app/bingo-world-wide/id291539020?mt=8" target="_blank">bingo
    · ·
  • meowmix23Fmeowmix23F Posts: 144Tutorial Authors
    edited February 2009
    If you don't need animation, then just use
    exit(0);
    

    But that will definitely not be accepted in the app store.
    Otherwise, the sharedApplication method should suffice.
    · ·
  • ayasinayasin Posts: 239Registered Users
    edited February 2009
    lbendlin wrote: »
    yes, it does work. To make the warning message go away use
    @interface UIApplication (extended)
    -(void) terminateWithSuccess;
    @end
    
    in the .h file.


    Now - is there a way to actually restart my app? ie terminate and start again?

    Yes, instead of using terminateWithSuccess, register a custom URL scheme and then use [[UIApplicaiton sharedApplication] openURL:somecustomurl]]; This will both exit your app and then restart it.
    <font size="2"><a href="http://www.pdascent.com/Site/iNeedStuff.html" target="_blank">iNeedStuff shopping assistant</a> - get in, get out, get on with your life</font>
    · ·
  • lbendlinlbendlin Posts: 429Registered Users
    edited February 2009
    just tried that, and sadly it doesn't work, at least not directly (when you call your own URL scheme). But I'll try to call a website which will auto-redirect to a page with my scheme. Let's see how that works.

    EDIT: It works via the Safari trick, but only with a remote server, as Apple helpfully (not!) do not allow to open local HTML files. So while it works in principle it does involve quite a few flashings and seconds.
    · ·
  • anuraganurag Posts: 143Registered Users
    edited February 2009
    I also need to know how the code below can be used to exit and relaunch our application.
    [[UIApplicaiton sharedApplication] openURL:somecustomurl]];
    
    And is this way of relaunching the application is acceptable by appStore?
    · ·
  • lbendlinlbendlin Posts: 429Registered Users
    edited February 2009
    as I said above - plant a redirect on a website you own. The redirect points to your registered URL scheme (in the info.plist). Then all you need to do is call Safari with the proper URL for the redirect.
    · ·
  • hstaniloffhstaniloff Posts: 133Registered Users
    edited May 2009
    @interface UIApplication (extended)
    -(void) terminateWithSuccess;
    @end

    When I put this code in my ...AppDelegate.h file, I get warnings in other parts of my code. Such as at:

    MyCodeAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];

    warning: type 'id <UIApplicationDelegate>' does not conform to the 'UIAlertViewDelegate' protocol

    Any ideas?
    Thanks...
    /H
    · ·
  • jtarajtara Posts: 406Registered Users
    edited May 2009
    But I want it.

    What? You want your app to be rejected by Apple?

    Because that is what will happen if you include an "exit" button.

    Every app already HAS an exit button: it's the "home" button. And Apple is very up-tight about that being the one and only way to exit an app. (Except for error conditions. e.g. your app need Location Services, but the user has it turned off in settings. You may exit the app after notifying the user that they need to turn Location Services on.)
    · ·
Sign In or Register to comment.