在 iPhone 或 iPad 应用程序中调用 main 时会发生什么?

发布于 2024-12-16 11:53:10 字数 331 浏览 3 评论 0原文

我目前正在尝试调试 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

把时间冻结 2024-12-23 11:53:10

当 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.

落日海湾 2024-12-23 11:53:10

我刚刚发现这个非常有趣。

I just found this which is pretty interesting.

浅唱々樱花落 2024-12-23 11:53:10

另请注意,如果您使用其中一个模板在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文