Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIScreen mirroredScreen property always returns nil

I want to present unique content on the external connected display if mirroring is not supported by the device (original iPad) but want to use screen mirroring if it's iPad 2. Now when I try to code this as follows:

if ([UIScreen instancesRespondToSelector:@selector(mirroredScreen)] && [[UIScreen mainScreen] mirroredScreen] == nil) {
    // Mirroring not supported. Present unique content on external display
}

[[UIScreen mainScreen] mirroredScreen] always returns nil.

Am I doing something wrong?

like image 964
Anupam Godbole Avatar asked Dec 12 '22 14:12

Anupam Godbole


1 Answers

As I understand the documentation, mirroredScreen will reference the main screen if you access the property on a secondary screen that actually is the mirrored screen. As in:

if ([[UIScreen screens] count] > 1) {
    UIScreen *secondaryScreen = [[UIScreen screens] objectAtIndex:1];
    NSLog(@"%@", secondaryScreen.mirroredScreen); // will reference the mainScreen
}

[[UIScreen mainScreen] mirroredScreen] would then always return nil because the mainScreen does not mirror itself.

like image 125
Ole Begemann Avatar answered Dec 29 '22 06:12

Ole Begemann