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.

Kev
  • 118,037
  • 53
  • 300
  • 385
Carl Veazey
  • 18,392
  • 8
  • 66
  • 81
  • 2
    @CarlVeazey In this case with my answer below I would recommend displaying a message that states the reason mirroring is "not working". – Chris Wagner Dec 07 '11 at 22:51

2 Answers2

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

Chris Wagner
  • 20,773
  • 8
  • 74
  • 95
  • Thanks Chris. I've been able to accomplish my goal with your advice. – Carl Veazey Dec 07 '11 at 23:51
  • 2
    @Chris not necessarily a "really really bad idea". I'm developing an app right now with a good reason for disabling mirroring. – DuckMaestro Mar 09 '12 at 23:37
  • There are always business reasons that make sense, it just sucks from a user's standpoint when functionality is crippled. – Chris Wagner Mar 09 '12 at 23:49
  • Hi @ChrisWagner, Kev, Carl, I have the same kind of requirement. Can you please share the code. Check this: http://stackoverflow.com/questions/11591928/how-to-disable-some-part-to-be-displayed-as-tvout-in-ios-5 But this solution not worked for me in a general way – Mrunal Aug 17 '12 at 11:17
  • 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. – Chris Wagner Aug 17 '12 at 19:34
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];
    }
Asadullah Ali
  • 1,056
  • 14
  • 31