最終更新:2024-04-09 (火) 02:59:16 (10d)  

UIApplicationDelegate application:didFinishLaunchingWithOptions:
Top / UIApplicationDelegate application:didFinishLaunchingWithOptions:

ウィンドウ (UIWindow)の作成や、呼び出すViewControllerを作成

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

オプション

  • 引数には通常 nil が渡ってくるが、他のアプリから呼び出した場合は NSDictionary が渡される
    NSString *const UIApplicationLaunchOptionsURLKey;
    NSString *const UIApplicationLaunchOptionsSourceApplicationKey;
    NSString *const UIApplicationLaunchOptionsRemoteNotificationKey;
    NSString *const UIApplicationLaunchOptionsAnnotationKey;
    NSString *const UIApplicationLaunchOptionsLocalNotificationKey;
    NSString *const UIApplicationLaunchOptionsLocationKey;
    NSString *const UIApplicationLaunchOptionsNewsstandDownloadsKey;

Xcode 4/プロジェクトテンプレート

Empty Application

  • - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        // Override point for customization after application launch.
        self.window.backgroundColor = [UIColor whiteColor];
        [self.window makeKeyAndVisible];
        return YES;
    }

Utility Application

  • - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        // Override point for customization after application launch.
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
            self.mainViewController = [[MainViewController alloc] initWithNibName:@"MainViewController_iPhone" bundle:nil];
        } else {
            self.mainViewController = [[MainViewController alloc] initWithNibName:@"MainViewController_iPad" bundle:nil];
        }
        self.window.rootViewController = self.mainViewController;
        [self.window makeKeyAndVisible];
        return YES;
    }

Single View Application

  • Storyboardを使う場合
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        // Override point for customization after application launch.
        return YES;
    }
  • Storyboardを使わない場合
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        // Override point for customization after application launch.
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
            self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];
        } else {
            self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
        }
        self.window.rootViewController = self.viewController;
        [self.window makeKeyAndVisible];
        return YES;
    }

Master-Detail Application

  • - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        // Override point for customization after application launch.
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
            UISplitViewController *splitViewController = (UISplitViewController *)self.window.rootViewController;
            UINavigationController *navigationController = [splitViewController.viewControllers lastObject];
            splitViewController.delegate = (id)navigationController.topViewController;
        }
        return YES;
    }

関連