ios external display programmatically
===

i'm trying to support external display on my iOS app without using any .xib files.

right now my code contains this:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ 
        if ([[UIScreen screens] count] > 1){
            externalScreen = [[UIScreen screens] objectAtIndex:1];
            UIScreenMode *current = [[[[UIScreen screens]objectAtIndex:1]availableModes]objectAtIndex:0];
            externalScreen.currentMode = current;
            externalWindow = [[UIWindow alloc] initWithFrame:[externalScreen bounds]];
            externalWindow.screen = externalScreen;
            externalWindow.clipsToBounds = YES;
        
            extController = [[ExternalController alloc] init];
            [externalWindow addSubview:extController.view];
            [externalWindow makeKeyAndVisible];
        }
        self.window = [[UIWindow alloc] initWithFrame:[[[UIScreen screens] objectAtIndex:0] bounds]];

        mainController = [[ViewController alloc] init];
        [self.window addSubview:mainController.view];
        self.window.backgroundColor = [UIColor whiteColor];
        [self.window makeKeyAndVisible];
    }

when i run this, the TV Out screen will close immediately.
If i comment this line:

    //self.window = [[UIWindow alloc] initWithFrame:[[[UIScreen screens] objectAtIndex:0] bounds]];

the TV Out screen will work properly, but of course i don't see anything on my simulator screen.

Does anyone have any idea what I should do? Thanks in advance!