Screen Mirroring on iPad

Tagged:  

The iPad supports an external display with the UIScreen and UIScreenMode classes as described in the What's New in iPhone OS document. This is intended for applications to present two different views on two different windows. For example presentation slides on the external display and notes on the iPad screen or video and images on the external display and controls on the iPad.

Sometimes it can be useful to mirror the iPad screen on the external display. This is not directly supported but luckily I found the iphoneos screen mirroring project by Francois Proulx on Google Code. It essentially sets up window and view on the external display and then uses the "blessed" UIGetScreenImage to periodically copy an image over from the internal display.

The easiest way to use it is to add it to your project, add the -ObjC -all_load other linker flags and include the header.

#import "UIApplication+ScreenMirroring.h"

Then when you are ready to start mirroring just call.

[[UIApplication sharedApplication] setupScreenMirroring];

When you are ready to stop call

[[UIApplication sharedApplication] disableScreenMirroring];

It is not a perfect solution as it is no where near as fast as you might like, and it is particularly slow for games, but it is easy to set up and incredibly useful for demos and presentations.

Also, I do not know how or if this would affect the approval process. It seems to be using legal methods in an unconventional unintended way and you never know.

To date, I have used it only for demos and it has been a lifesaver. Let me know how it works for you.

Hi there,

Great code, and very useful indeed - thanks! However, I am looking to use this for a demo which has a number of animations, such as view transitions etc - and noticed that as it is, it's a bit slow - i was wondering if there was a way to improve this at all? I have been looking at changing the params for frame intervals etc etc, but none of that seems to make much different - assuming that it's consuming a lot of CPU cycles to do all of this at the moment...

Any ideas at all? Would be very grateful!

Thanks in advance

Since it just copies images and there is no hardware driving the external monitor, I'm not aware of any techniques that would significantly improve the performance of this approach. Let us know if you find something.

When I try and build my code with this linked in I get the following errors: Any Ideas? I'm using Xcode 3.2.3

Undefined symbols:
"_kCAGravityResizeAspect", referenced from:
_kCAGravityResizeAspect$non_lazy_ptr in UIApplication+ScreenMirroring.o
(maybe you meant: _kCAGravityResizeAspect$non_lazy_ptr)
"_CATransform3DIdentity", referenced from:
_CATransform3DIdentity$non_lazy_ptr in UIApplication+ScreenMirroring.o
(maybe you meant: _CATransform3DIdentity$non_lazy_ptr)
"_OBJC_CLASS_$_CADisplayLink", referenced from:
objc-class-ref-to-CADisplayLink in UIApplication+ScreenMirroring.o
"_CATransform3DMakeRotation", referenced from:
-[UIApplication(ScreenMirroring) updateMirroredWindowTransformForInterfaceOrientation:] in UIApplication+ScreenMirroring.o
-[UIApplication(ScreenMirroring) updateMirroredWindowTransformForInterfaceOrientation:] in UIApplication+ScreenMirroring.o
-[UIApplication(ScreenMirroring) updateMirroredWindowTransformForInterfaceOrientation:] in UIApplication+ScreenMirroring.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

Looks like you may need to link in the core graphics and/or quartz core frameworks.

Thank you!
Adding the QuartzCore framework solved the build problem. No output on the VGA screen in the simulator though. Should this work on the simulator? Also do I need to target the iPad device in my project build settings?

This does not work in the simulator. I have not tried it on the iPhone 4. It was originally written for the iPad hardware.

Thanks again for the prompt reply . I don't have either here, Will check it out on a friends device. Much appreciated.

it's great code and I used it. but, it can not be seen full screen mode seems like keynote.. .. Do you have any solution?

It mirrors the iPad display and is not meant to fill the external display so no, it will not run full screen because the aspect ratios are different.

To get full screen output on the external display you have to create content specifically for the external display not for the iPad display and use a traditional approach outlined by Apple.

Hi there,

great code - wondered if anyone was using this on iPhone 3GS? Compiles and runs, but never seen any display output via the HD component cable - debugging it through the splitter cable it seems that it only ever finds 1 screen...anyone have any ideas?

Yes, this is for the iPad only at this time.

hello, i
I am interested in using this code, however i am a begginer and im not sure exactly where to call the code you mentioned. is it under void?
thanks

The problem has something to do with the Cocos2D template. Your method does work on a fresh app.

Thanks!

This doesn't seem to be working for me. When I call [[UIApplication sharedApplication] setupScreenMirroring]; the app terminates with an uncaught exception, -[UIApplication setupScreenMirroring]: unrecognized selector sent to instance.

It is is category so you need to remember to set the -ObjC -all_load other linker flags for all your targets.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <h2> <img> <p>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options