"Close" also terminate app - bad form?

Discussion in 'Mac Programming' started by Danneman101, Jan 26, 2011.

  1. Danneman101 macrumors 6502

    Joined:
    Aug 14, 2008
    #1
    My application only has one window which is the whole program. Therefore I would like the whole app to terminate when the user clicks any of the close-buttons (which by default only closes the actual window).

    How can this be achieved? And is it frowned upon by Apple (who will be the ones approving my app)? I can't think of any one program that terminates the whole app when clicking close, but then again I'm not an avid mac-user...
     
  2. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #2
    If you are not an experienced Mac user (and even if you are), go to developer.apple.com, have a good look around, and find whatever user interface guidelines you can find and study them carefully. They tell you both what to do and how to do it.
     
  3. GorillaPaws macrumors 6502a

    GorillaPaws

    Joined:
    Oct 26, 2003
    Location:
    Richmond, VA
    #3
    It depends on the app. I like to close the last window on many apps, but keep them running in the background so I can open a new window without having to re-launch the application. Look at the behavior of iTunes, which is also a single-window interface. You can close the window and keep it running in the background, but if the user selects iTunes in the dock, it will create a new window and bring it forward. System Preferences behaves differently, and will quit on closing the window.

    Code:
    -(BOOL) applicationShouldTerminateAfterLastWindowClosed: (NSApplication *)sender
    {
    	return YES;
    }
    
    Include the above code in the App Delegate's implementation to generate the behavior you're looking for. I find it useful to activate during development, but would only implement it under very specific circumstances in a shipping app. I would carefully review the documentation for specifics on when it's ok to use this behavior.
     
  4. Danneman101 thread starter macrumors 6502

    Joined:
    Aug 14, 2008
    #4
    GorillaPaws:

    It seems to be appropriate to single-window applications, such as mine (and like App Store, which I found worked like this). So this function works perfectly - thank you :)

    I also disabled and hid the "File" toolbar in the xib since they fill no function in a single-window app.


    gnasher729: Yes, I've been browsing those documents a lot lately, and they are indeed helpful :)
     
  5. GorillaPaws, Jan 26, 2011
    Last edited: Jan 26, 2011

    GorillaPaws macrumors 6502a

    GorillaPaws

    Joined:
    Oct 26, 2003
    Location:
    Richmond, VA
    #5
    Points to consider:
    If your app takes more than 1 or 2 seconds to launch, I wouldn't use this behavior. People are impatient and might want to have it running in the background to save themselves waiting for your app to launch (remember Mac users have different usage patterns than PC users--and they tend to be more passionate about these types of usability details).

    If your app has background processes that the user may want to have running while the main window is closed, then you shouldn't use this behavior. For example, Pandora's app will quit on window's closing which infuriates me. I either have to keep the window open, or have it take up space in my dock when minimized, either option will still clutter up my view when I use Expose. It's an exceedingly poor design (not to mention it runs on Adobe Air), and will launch Safari if clicked anywhere except the title bar to make it the active window.

    The issue is certainly more complex than finding one example where Apple has implemented a quit on last window close and then taking your cues from that. It's worth weighing the pro's and con's of each decision like this and figuring out how to make the best possible user experience. I would highly recommend reading/taking to heart the HIG before you release anything.
     
  6. Danneman101 thread starter macrumors 6502

    Joined:
    Aug 14, 2008
    #6
    GorillaPaws:

    Duly noted. My app takes less than a blink to open, and does not run any background-processes, so I think it's a good candidate for this behavior. Thanks for the heads-up, though :)

    I've skimmed trough most of the HIG, but I think I'll take a closer look at it again before releasing the app.
     
  7. whooleytoo macrumors 603

    whooleytoo

    Joined:
    Aug 2, 2002
    Location:
    Cork, Ireland.
    #7
    One difference is while iTunes is typically single-window app, you can also open other windows/dialogs (preferences, video windows). System Preferences is AFAIK strictly a single-window app. I don't know if that's why Apple chose for System Preferences to close and not iTunes, or if it's just Apple being Apple..
     

Share This Page