Proper way to exit iPhone application?

前端 未结 25 2735
难免孤独
难免孤独 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:45

    After some tests, I can say the following:

    • using the private interface : [UIApplication sharedApplication] will cause the app looking like it crashed, BUT it will call - (void)applicationWillTerminate:(UIApplication *)application before doing so;
    • using exit(0); will also terminate the application, but it will look "normal" (the springboard's icons appears like expected, with the zoom out effect), BUT it won't call the - (void)applicationWillTerminate:(UIApplication *)application delegate method.

    My advice:

    1. Manually call the - (void)applicationWillTerminate:(UIApplication *)application on the delegate.
    2. Call exit(0);.

提交回复
热议问题