Why doesn't an iPhone app's main() function ever get a chance to finish?

前端 未结 3 1650
长发绾君心
长发绾君心 2021-02-15 03:07

Consider the following main() method which you would find most iPhone applications:

int main(int argc, char *argv[])
{
    NSAutoreleasePool *pool =         


        
3条回答
  •  清歌不尽
    2021-02-15 03:44

    The original question was: "Why doesn’t an iPhone app’s main() function ever get a chance to finish?"

    Short Answer: Because UIApplicationMain() is coded such that it never returns.

    After doing several tests in Simulator and on the device, and asking another developer to do the same tests, I have confirmed that UIApplicationMain never returns. When the user terminates an application normally by hitting the Home button, The program ultimately terminates inside an unpublished UIApplication method called _terminateWithStatus. This method calls exit(0).

    This behavior matches that of the NSApplicationMain function (which is AppKit/Cocoa version of the UIApplicationMain function). The documentation for NSApplicationMain() clearly states that it will never return.

    I have submitted a bug (6600198) to Apple requesting that the official documentation (and Xcode template for main.m) be corrected to state that UIApplicationMain() never returns. While this is not a functional problem, the current template and docs are misleading.

    Thanks to everyone for all the input and brainstorming!

提交回复
热议问题