IOS 어플리케이션 시작 프로세스

3032 단어
프로그램 입구는main 함수이며, 다음은 원시적으로 변경되지 않은main 함수를 예로 들겠습니다.
int main(int argc, char * argv[]) {
    @autoreleasepool {
         NSLog(@"%s",__func__);
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
       
    }
}
  • main 함수에서 UIAPplicationMain(int argc,char*argv[],NSString* nullable principalClassName,NSString* nullable delegateClassName)이 호출됩니다.셋째, 네 번째 파라미터는 주요 클래스와 프록시 클래스를 대표하고 주요 클래스가 nil이면 기본값은 UIAPplication이며 프록시 클래스가 nil이면 Main nib 파일에서 프록시 대상을 불러옵니다.UIApplication 객체는 어플리케이션의 라이프 사이클을 모니터링하고 에이전트가 수신된 이벤트를 처리합니다.
  • 응용 프로그램은 주 운행 순환을 열고 이벤트 처리를 진행합니다(먼저 시작이 끝난 후 에이전트 대상을 호출하는 다음과 같은 방법)
  • - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(nullable NSDictionary *)launchOptions

    이 방법에서는 프레임, 프록시 대상의 주 창, 그리고 UIWindow의 루트 보기 컨트롤러를 설정하여 주 창을 표시하고, 프로그램은 루트 보기 컨트롤러의 구체적인 상황에 따라 대응하는 View를 주 창에 불러옵니다.
        3.UIApplication 프록시 객체 중 라이프 사이클과 관련된 부분은 다음과 같습니다.
    a. 응용 프로그램이 비활성 상태에 들어갔을 때 호출되며, 이 기간에 메시지나 이벤트를 받지 않습니다. 예를 들어 전보를 보냅니다.
    - (void)applicationWillResignActive:(UIApplication *)application {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
    }

    b. 프로그램이 백그라운드로 전송될 때 호출되며 백그라운드가 계속 실행되도록 설정하려면 이 방법에서 설정할 수 있습니다
    - (void)applicationDidEnterBackground:(UIApplication *)application {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }

    c. 프로그램이 백엔드에서 프론트 데스크톱으로 실행될 때 호출됩니다.
    - (void)applicationWillEnterForeground:(UIApplication *)application {
        // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
    }

    d. 프로그램이 활성 상태일 때 실행되며 메시지나 이벤트를 수신할 수 있습니다
    - (void)applicationDidBecomeActive:(UIApplication *)application {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }

    e. 프로그램이 종료될 때 호출되며, 보통 데이터를 저장하고 청소합니다
    - (void)applicationWillTerminate:(UIApplication *)application {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
    }

    좋은 웹페이지 즐겨찾기