Proper way to exit iPhone application?

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

    Your ApplicationDelegate gets notified of intentional quitting by the user:

    - (void)applicationWillResignActive:(UIApplication *)application {
    

    When I get this notification I just call

            exit(0);
    

    Which does all the work. And the best thing is, it is the useres intent to quit, which is why this should not be a problem calling it there.

    On my Audio-App it was necessary to quit the app after people were syncing their device while the music was still playing. As soon as the syncing is complete I get a notification. But quitting the app right after that would actually look like a crash.

    So instead I set a flag to REALLY quit the app on the next backgrounding action. Which is okay for refreshing the app after a sync.

提交回复
热议问题