【问题标题】:Which method and function is called first when any iOS application start?任何 iOS 应用程序启动时首先调用哪个方法和函数?
【发布时间】:2011-06-29 17:23:24
【问题描述】:

任何 iOS 应用程序启动时首先调用哪个方法和函数?

【问题讨论】:

    标签: ios application-lifecycle


    【解决方案1】:

    我猜是

    int main(int argc, char *argv[])
    

    main.m 文件中

    但出于实际目的,我认为您通常需要根据情况实现一些 UIApplicationDelegate 的方法:

    application:didFinishLaunchingWithOptions:
    applicationDidBecomeActive:
    applicationWillEnterForeground:
    

    【讨论】:

    • main 是一个函数,而不是一个方法。这不是 Ruby。
    【解决方案2】:

    如果一个 View 启动了,那么它是:

    - (void)viewDidLoad {}
    

    如果一个应用启动它是:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
    

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

    我认为你最好使用 ViewDidLoad 方法。

    希望我能帮上忙!

    【讨论】:

    • 您的回答真的很有帮助。谢谢。
    【解决方案3】:

    其实:

    - (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions{}
    

    出现在:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{}
    

    【讨论】:

      【解决方案4】:

      应用程序启动时,首先应用程序:didFinishLaunchingWithOptions: 方法被调用..

      视图启动后

      ​​>

      此时 viewDidLoad 被执行;

      【讨论】:

        【解决方案5】:

        应用启动期间调用的第一个函数

        int main(int argc, char *argv[])

        应用启动期间调用的第一个方法

        application(_:willFinishLaunchingWithOptions:)

        UIKit 处理大部分应用启动任务。

        1) The app is launched, either explicitly by the user or implicitly by the system.
        
        2) The Xcode-provided main function calls UIKit's UIApplicationMain() function.
        
        3) The UIApplicationMain() function creates the UIApplication object and your app delegate.
        
        4) UIKit loads your app's default interface from the main storyboard or nib file.
        
        5) UIKit calls your app delegate's application(_:willFinishLaunchingWithOptions:) method.
        
        6) UIKit performs state restoration, which calls additional methods of your app delegate and view controllers.
        
        7) UIKit calls your app delegate's application(_:didFinishLaunchingWithOptions:) method.
        
        

        参考 - https://developer.apple.com/documentation/uikit/app_and_environment/responding_to_the_launch_of_your_app/about_the_app_launch_sequence

        【讨论】:

          【解决方案6】:

          Have look at image 根据苹果文档

          • (BOOL)应用程序:(UIApplication *)应用程序 willFinishLaunchingWithOptions:(NSDictionary *)launchOptions{}

          在之前被调用

          • (BOOL)应用程序:(UIApplication *)应用程序 didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{}

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2017-11-07
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多