An iOS UIView subclass that records its contents to MPEG-4 video.
To use this code simply add the sources to your project and then ensure that your build includes the following Frameworks:
- AssetsLibrary
- AVFoundation
- CoreGraphics
- CoreMedia
- CoreVideo
- QuartzCore
To use this code, you must perform the following steps:
-
Set up an
IAScreenCaptureView
instance as the parent view of the view(s) you want to record. -
Implement the
IAScreenCaptureViewDelegate
protocol and set thedelegate
property on yourIAScreenCaptureView
instance (this step is optional; you only need to do it if you care about getting your captured video output). -
Call
startRecording
when you are ready to start capturing video. -
Call
stopRecording
when you are done recording video. Your delegate will receive the path to the completed video file, which you can then copy off to wherever you prefer.
Note that you can also call currentScreen
to grab a screenshot of the view's current state. This works whether or not you are currently recording.
There are a few limitations to be aware of when using this class:
-
If you want to record a
UIScrollView
you need to implement yourUIScrollViewDelegate
such that it callssetNeedsDisplay
on theIAScreenCaptureView
while theUIScrollView
is scrolling. -
Currently only video is captured. It should be possible to capture audio as well as video, but I have not had time to add this functionality. If you happen to add it, feel free to send a pull request.
-
I have not tested this class to see if it can record OpenGL-based views. I suspect that it probably cannot, however.
-
I have not tested this code heavily on actual iOS devices (it's primarily seen duty in the iOS simulator). It should run, but I cannot make any guarantees with respect to its level of performance. I would not expect it to be particularly fast or particularly light on battery consumption.
Why create this utility?
It's a funny story, actually. I was reviewing some work submitted by an overseas contractor; it was full of bugs, the vast majority graphical. Many of them only appeared when interacting with the UI in a particular way. Textual descriptions of the issues were too clunky, and even screenshots were inadequate at properly documenting and describing the nature of the issues. So I implemented this class so that I could quickly and easily record a video for each UI bug that I found.
That said, this thing probably works just as well at creating demo videos as it does for pointing out bugs.
Why should I use this library?
This code works reasonably well for capturing screen content. Use it if you want to do that.
Why should I NOT use this library?
Don't use this code if you don't need to record your app's screen content. Also don't use it if you want your app to run fast and not waste the device's battery. Pertty much don't use it in production at all, unless you're building a screen-capture app.
What are your license terms?
Use this code if you want, otherwise don't. That's it.