19

Is it possible to mirror the Screen over the VGA Connector? Can't find anything about this.

x2on
  • 2,237
  • 3
  • 23
  • 44

3 Answers3

34

I was looking for the same thing you are. Last weekend I wrote a small UIApplication category to add mirroring support. I published to code on Google Code.

http://code.google.com/p/iphoneos-screen-mirroring/

To use it, you simply have to set it up in your application delegate's app did finish lauching. Like so:

[[UIApplication sharedApplication] setupScreenMirroringOfMainWindow:mainWindow framesPerSecond:20];

I only had one chance to try it out last weekend on a big screen TV with the Apple AV output cables. The performance is not stellar, thus I would not recommend using a frame rate higher than 30 fps...

François P.
  • 5,136
  • 4
  • 30
  • 31
  • Does not work here. Only black screen with [[UIApplication sharedApplication] setupScreenMirroringOfMainWindow:window framesPerSecond:20]; How can i debug with VGA-Adapter on iPad? – x2on Apr 20 '10 at 06:50
  • The new version works with [[UIApplication sharedApplication] setupScreenMirroringWithFramesPerSecond:20.0]; but it is very slow. – x2on Apr 21 '10 at 14:52
  • I've pushed a new version that copies using the CALayer directly. I'll see if the performance is better tomorrow (could not try tonight as the dev iPad is gone). – François P. Apr 22 '10 at 18:11
  • Also, the new version runs a different NSRunLoop mode so it can grab pictures while you touch the screen, though it has a strong impact on performance (steals some CPU time to the UIScrollView deceleration timer etc...) – François P. Apr 22 '10 at 18:13
  • The new version does not work here. The application crash when an screen is attached. (Low memory) – x2on Apr 23 '10 at 06:42
  • It should work better now. Ooops fixed a big bad leak. I missed a CFRelease(mainWindowScreenshot); That's because UIGetScreenImage does NOT respect retain / release semantics. :-( – François P. Apr 23 '10 at 08:59
  • This works quite well for iPhone as well on OS4 beta. The screen is centered on the external display but clipped. Is there a way to scale the screen to fit? – mvexel May 31 '10 at 08:01
  • Hi, thanks for the code, but when you rotate the device, the screen beyond what is being mirrored flickers with some frames of the rotating animation and also the image is squeezed vertically. A circle on iPhone looks like an ellipse on TV. – Duck Sep 30 '10 at 16:13
  • 3
    As others have noted, this uses the once-again private `UIGetScreenImage()` API and will lead to a rejection if you submit an application with this to the App Store. – Brad Larson Dec 09 '10 at 17:04
5

I think it worth adding that the QuartzCore framework is mandatory, or you'll have 4 errors at compile time.

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

Each UIWindow object (basically the top level view) is assigned a screen (UIScreen) and you can of course set the screen you want. Therefore moving the main content to a second screen is easy, but mirroring is hard. (If you don't want a lecture on why it's ugly skip until the next paragraph) I believe this is apple's intention, both because drawing the same thing twice, one with a MUCH higher resolution, and because the experience of watching the interface before entering whatever presentation mode is rather subpar in comparison to seeing nothing until the video is playing, keynote presentation has started, etc. This is something you obviously want to consider on a case by case basis, but nonetheless mirroring is a Bad Idea.

UIWindow inherits from UIView, so although I don't have much personal experience with this exact thing, you should still be able to get it to draw to a bitmap context of some kind, and then use two different UIWindows each with only an image view on a them pushing the actual pixels to their respective screens. This is considerably easier if you only want to mirror one specific custom view (and not including it's subviews) because you can have that view on the device screen, (to capture any input) and then design it in a way that you have a method to call to draw it in whatever context it's in (some drawRects might work fine as is) and the call that from a super special awesome custom subview on the other screen, which would implement drawRect to just call the method on the actual view.

Hope this helps, sorry I ranted a bit :(

Jared Pochtar
  • 4,727
  • 2
  • 23
  • 38
  • Why do you say "one with a MUCH higher resolution"? I just hooked to a projector yesterday and it defaults to 1024x768 which is the same as the iPad. I wish by default it mirrored unless your app decided to display something else on the external. It would be really sweet for showing off application concepts. – jamone Apr 19 '10 at 19:49
  • While I agree that it would be cool for showing off the apps, keep in mind that apple doesn't think thats what people are going to be using this for primarily :P However, if you don't mind not seeing the screen on the iPad when its hooked up to an external display, its really easy to move the main UIWindow to the other UIScreen -- http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIScreen_Class/Reference/UIScreen.html – Jared Pochtar Apr 19 '10 at 20:49
  • Does it works on the simulator 4.2?? I've tried using this code on simulator with T.V out..but nothing shows up.. :( – Hisenberg Feb 16 '11 at 14:37