Я собираюсь добавить возможности AirPlay в один из моих ViewController. Контроллер представления просто показывает UIWebView. Я хочу добавить кнопку, которая будет отображать этот контент на Apple TV. Я знаю, что можно сделать общесистемное зеркальное отображение, но оно не заполняет весь экран, вокруг есть черные полосы. Я искал в Интернете, но почти все, что я нашел, давно прошло от iOS 5 и устарело. Может ли кто-нибудь указать мне на руководство или библиотеку, которая могла бы помочь? Мне просто нужно, чтобы он отображал содержимое всего одного просмотра в полноэкранном режиме на Apple TV.
Пока что я сделал вот что, но я считаю, что он создает только второе окно, ничего не помещая в него.
В AppDelegate я создаю для него свойство:
@property (nonatomic, retain) UIWindow *secondWindow;
В методе didFinish AppDelegate я запускаю:
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self selector:@selector(handleScreenDidConnectNotification:)
name:UIScreenDidConnectNotification object:nil];
[center addObserver:self selector:@selector(handleScreenDidDisconnectNotification:)
name:UIScreenDidDisconnectNotification object:nil];
Тогда в AppDelegate у меня есть:
- (void)handleScreenDidConnectNotification:(NSNotification*)aNotification
{
UIScreen *newScreen = [aNotification object];
CGRect screenBounds = newScreen.bounds;
if (!self.secondWindow)
{
self.secondWindow = [[UIWindow alloc] initWithFrame:screenBounds];
self.secondWindow.screen = newScreen;
// Set the initial UI for the window.
}
}
- (void)handleScreenDidDisconnectNotification:(NSNotification*)aNotification
{
if (self.secondWindow)
{
// Hide and then delete the window.
self.secondWindow.hidden = YES;
self.secondWindow = nil;
}
}
В viewController, в котором я хотел бы разрешить зеркальное отображение WebView на Apple TV, у меня есть:
- (void)checkForExistingScreenAndInitializeIfPresent
{
if ([[UIScreen screens] count] > 1)
{
// Get the screen object that represents the external display.
UIScreen *secondScreen = [[UIScreen screens] objectAtIndex:1];
// Get the screen's bounds so that you can create a window of the correct size.
CGRect screenBounds = secondScreen.bounds;
appDelegate.secondWindow = [[UIWindow alloc] initWithFrame:screenBounds];
appDelegate.secondWindow.screen = secondScreen;
// Set up initial content to display...
// Show the window.
appDelegate.secondWindow.hidden = NO;
NSLog(@"YES");
}
}
Все это я получил от здесь. Однако это все, что он показывает, поэтому я не уверен, как вывести контент на этот экран.