Block AirPlay Mirroring on iOS 5
Asked Answered
R

2

7

On iOS 5 with an iPad 2 or iPhone 4S, users can enable screen mirroring with their Apple TV and AirPlay. How can I prevent my app from being mirrored in this way? Is there any way to detect that this mirroring is taking place so I can prevent my content from being mirrored?

The reason for doing this is because I have content I'm not legally allowed to display on a television screen.

Rode answered 7/12, 2011 at 22:23 Comment(1)
@CarlVeazey In this case with my answer below I would recommend displaying a message that states the reason mirroring is "not working".Annecy
A
5

This is a really really bad idea and I hate it as you are inhibiting your users. With that said, AirPlay mirroring works the same way as connecting the VGA/HDMI adapter, when you connect an adapter you have the ability to display whatever you want on the "second monitor". If you want to "block" mirroring you could set the external display's window to a blank/solid black view.

Most iOS applications create and use only one window during their lifetime. This window spans the entire main screen of the device and is loaded from the application’s main nib file (or created programmatically) early in the life of the application. However, if an application supports the use of an external display for video out, it can create an additional window to display content on that external display. All other windows are typically created by the system, and are usually created in response to specific events, such as an incoming phone call.

Check out the View Programming Guide for iOS, specifically the Windows section and Displaying Content on an External Display

Annecy answered 7/12, 2011 at 22:30 Comment(5)
Thanks Chris. I've been able to accomplish my goal with your advice.Rode
@Chris not necessarily a "really really bad idea". I'm developing an app right now with a good reason for disabling mirroring.Saito
There are always business reasons that make sense, it just sucks from a user's standpoint when functionality is crippled.Annecy
Hi @ChrisWagner, Kev, Carl, I have the same kind of requirement. Can you please share the code. Check this: #11592428 But this solution not worked for me in a general wayAesthetics
Sorry mrunal, I do not have a code example for this. If you are having issues with some code you've written you may want to open a new question with your code so someone can assist you in fixing the problem.Annecy
L
2

Just to add the code for doing this pretty simple work Here

if ([[UIScreen screens] count] > 1)
    {
        UIScreen *secondScreen = [[UIScreen screens] objectAtIndex:1];
        CGRect screenBounds = secondScreen.bounds;
        UIWindow *secondWindow = [[UIWindow alloc]initWithFrame:screenBounds];
        secondWindow.screen = secondScreen;
        UIView *anyView= [[UIView alloc]initWithFrame:screenBounds];
        anyView.backgroundColor= [UIColor blackColor];
        [secondWindow addSubview:anyView];
    }
Loosestrife answered 2/5, 2015 at 22:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.