Proper way to exit iPhone application?

前端 未结 25 2685
难免孤独
难免孤独 2020-11-22 01:54

I am programming an iPhone app, and I need to force it to exit due to certain user actions. After cleaning up memory the app allocated, what\'s the appropriate method to ca

相关标签:
25条回答
  • 2020-11-22 02:33

    Exit an app other way than the home button is really non-iOS-esque approach.

    I did this helper, though, that use no private stuff:

    void crash()
    { [[NSMutableArray new] addObject:NSStringFromClass(nil)]; }
    

    But still not meant for production in my case. It is for testing crash reportings, or to fast restart after a Core Data reset. Just made it safe not to be rejected if function left in the production code.

    0 讨论(0)
  • 2020-11-22 02:35

    Its not really a way to quit the program, but a way to force people to quit.

    UIAlertView *anAlert = [[UIAlertView alloc] initWithTitle:@"Hit Home Button to Exit" message:@"Tell em why they're quiting" delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
    [anAlert show];
    
    0 讨论(0)
  • 2020-11-22 02:38

    This has gotten a good answer but decided to expand a bit:

    You can't get your application accepted to AppStore without reading Apple's iOS Human Interface Guidelines well. (they retain the right to reject you for doing anything against them) The section "Don't Quit Programmatically" http://developer.apple.com/library/ios/#DOCUMENTATION/UserExperience/Conceptual/MobileHIG/UEBestPractices/UEBestPractices.html is an exact guideline in how you should treat in this case.

    If you ever have a problem with Apple platform you can't easily find a solution for, consult HIG. It's possible Apple simply doesn't want you to do it and they usually (I'm not Apple so I can't guarantee always) do say so in their documentation.

    0 讨论(0)
  • 2020-11-22 02:39

    The user should decide when an app exits. I don't think it is a good user interaction when an app quits. Therefore there is no nice API for it, only the home button has one.

    If there is an error: Implement it better or Notify the user. If there have to be a restart: Implement it better of Notify the user.

    It sounds dumb, but it's bad practice to exit the app without letting the user decide and not notifying him. And since there is a home button for the user interaction, Apple states, there should not be 2 things for the same function (exiting an app).

    0 讨论(0)
  • 2020-11-22 02:41

    Go to your info.plist and check the key "Application does not run in background". This time when the user clicks the home button, the application exits completely.

    0 讨论(0)
  • 2020-11-22 02:41

    Add UIApplicationExitsOnSuspend property on application-info.plist to true.

    0 讨论(0)
提交回复
热议问题