在 iPhone 或 iPad 应用程序中调用 main 时会发生什么?
我目前正在尝试调试 iPhone 应用程序的问题。当我在 Xcode 中运行它时,main
被调用,但不是 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
。这引出了一个基本问题,它应该可以帮助我解决这个问题,但也可以更多地了解 iPhone/iPad 应用程序的启动顺序。那么,谁能简单地解释一下在 iPhone 或 iPad 应用程序中调用 main 时会发生什么?
谢谢!
I am currently trying to debug a problem with an iPhone app. When I run it in Xcode main
is called, but not - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
. This leads me to an essential question which should help me resolve this problem, but also understand more the startup sequence of an iPhone/ iPad application. So, can anyone explain in a succinct manner what happens when main is called in an iPhone or iPad app?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当 main 被调用时,
UIKIT_EXTERN int UIApplicationMain(int argc, char *argv[], NSString *principalClassName, NSString *delegateClassName);
被称为。
以下是苹果公司对这种方法的评价。
如果为principalClassName 指定nil,则使用Info.plist 中的NSPrincipalClass 值。如果没有指定 NSPrincipalClass 键,则使用 UIApplication 类。委托类将使用 init 实例化。
您可以在 main.h 或 info.plist 中检查这些条目。
When main is called,
UIKIT_EXTERN int UIApplicationMain(int argc, char *argv[], NSString *principalClassName, NSString *delegateClassName);
is called.
Here is what Apple has to say for this method.
If nil is specified for principalClassName, the value for NSPrincipalClass from the Info.plist is used. If there is no NSPrincipalClass key specified, the UIApplication class is used. The delegate class will be instantiated using init.
You can check these entries in the main.h or the info.plist.
我刚刚发现这个非常有趣。
I just found this which is pretty interesting.
另请注意,如果您使用其中一个模板在 Xcode 中创建一个新项目,Xcode 将构建一个非常好的 main 方法,该方法肯定会为您调用 didFinishLaunchWithOptions,您可以分析并遵循 Xcode 的引导。
Note also that if you create a new project in Xcode with one of the templates, Xcode will build a very nice main method that will definitely call didFinishLaunchWithOptions for you, which you can analyze and follow Xcode's lead.