iOS Screen Capture View

iOS Screen Capture View

Released 5 years ago , Last update 1 month ago

Screen Capture View is a control used to record real-time video and take screen snapshots of any view and it's subviews. Create a video of your app with optional audio. Acquire various screenshots with optional status bar. This package includes full source code and a working demo.

UIScreenCaptureView, a UIView subclass that records real-time video of the screen or a subview. The sample/update rate can be configured by calling setFrameRate. Can include audio for global sounds (app, microphone, etc) with recorded video. To include audio call includeAudio.

Create a video of a view or full screen with status bar or full screen without the status bar area. By default, the view and it's subviews are recorded. Get a screen snapshot at any time of a view, full screen with status area or full screen without status area.

By default, all screen snapshots are now done on a background thread to free up the UI main thread. A flag in UIScreenCaptureView class lets you switch between running snapshot on background or main thread.

This class can also be used to record real-time video of its subviews, using the startRecording and stopRecording methods. A new recording will overwrite any previously made recording file, so if you want to create multiple recordings per session (or across multiple sessions) then it is your responsibility to copy/back-up the recording output file after each session.

You can also use startRecordingForTimePeriod to record for specified number of seconds.

Use setOutputName to specify your own output filename. The default filename is output.mp4.

Use setVerbose to turn debug mode on or off.

When the recording stops, UIScreenCaptureView calls your code's UIScreenCaptureViewDelegate method recordingFinished:(NSURL *)outputPathOrNil. If the output URL is not nil then you can save, play or do whatever you need to do with the created video recording. UIScreenCaptureView has a built-in video player which you can use by calling [UIScreenCaptureView playVideo:outputPathOrNil parent:self]. If the output URL is nil then an error occurred.

 

Sample Code

// Recording the screen
//
// Create screen capture view. Any subviews added to screen capture view will be recorded.
int captureViewWidth = self.view.width;
int captureViewHeight = self.view.height;
BOOL fullScreen = TRUE; // if recording full screen can record fullscreen with/without status bar
BOOL includeStatusBar = FALSE: // do not include statusBar
BOOL includeAudio = TRUE; // whether to include audio with recording or not.
// Can be your spoken voice or any audio being played when recording.

// create the screen caoture view with out options...
UIScreenCaptureView * screenCaptureView = [[UIScreenCaptureView alloc] initWithFrame:CGRectMake(0, 0, captureViewWidth, captureViewHeight)] parent:self fullscreen:fullscreen includeStatusBar:incldueStatusBar];

// Recording options:
[screenCaptureView includeAudio:includeAudio]; // indicates audio
[screenCaptureView setFrameRate:15.0f]; // 15 frames per second (10 fps the default) (frame rate)
[screenCaptureView setOutputName:@"video.mp4"]; // output name (output.mp4 is the default)

[screenCaptureView setVerbose:TRUE]; // verbose debug mode
screenCaptureView.delegate = self; // implements UIScreenCaptureViewDelegate interface
self.view = screenCaptureView; // if make main view then should add app subviews to it so can record the full app window. If you add the screenCaptureView as a subview of any of your windows, then only the subviews of the screenCaptureView are recorded. Note: Videos are currently is not recorded.
//
// e.g or can do
// [self.view addSubview:screenCaptureView]; // this one will let record any subview of screenCaptureView
//
// recording until we stop recording...
[screenCaptureView startRecording]; // start recording the video

// recording for a special number of seconds:
// can also start recording for a specific time period e.g. 20 seconds or 3 minutes etc...
//[screenCaptureView startRecordingForTimePeriod:30]; // 30 seconds of recording then can recording done callback. If use this method use this method only with no stopRecording call unless want to stop recording early. When recording time perdiod has elapsed, stopRecording will be call automatically.
// So if use [screenCaptureView startRecording] need a matching [screenCaptureView stopRecording]
// So if use [screenCaptureView startRecordingForTimePeriod:x] don't need a matching stopRecording

// Getting a screenshot of the screen.
// Any of the screenshot methods can be called at anytime whether a recording is taking place or not.
//
// Take screen snapshot and return the resulting image
UIImage * screenSnapshot = [UIScreenCaptureView takeScreenSnapshot];

// Take screen snapshot and save the resulting image to photos
[UIScreenCaptureView takeScreenSnapshotAndSave];

// Take a screenshot and include status bar area and return the resulting image
UIImage * screenSnapshotWithStatusBar = [UIScreenCaptureView takeScreenshotWithStatusBar;

// Take a screenshot and do not include status bar area and return the resulting image
UIImage * screenSnapshotNoStatusBar = [UIScreenCaptureView takeScreenSnapshotWithNoStatusBar;

// Take a screenshot of a UIView
UIImage * screenSnapshotForView = [UIScreenCaptureView takeScreenSnapshotOfView:theView];

// Stop recording
[screenCaptureView stopRecording];
.
.
.

//
UIScreenCaptureViewDelegate methods
//
// Callback from UIScreenCaptureView when recording video has stopped/done
// recording has completed so save the video to photos.
- (void)recordingFinished:(NSURL *)outputPathOrNil {
BOOL includeAudio = [screenCaptureView includeAudio];

// output URL is present then the video was created successfully
if (outputPathOrNil != nil) { NSString * outputName = [outputPathOrNil path];
// you can then save, play the recorded video etc...
// save the created video to Photos... [screenCaptureView saveToPhotos:outputName target:self]; // Other options for the creatd video: // Typically you just want to save the video to your Photos // but you can also play the recorded video or remove the local copy // of the video after you savd to Photos. // Uncomment the following line to 'play the recorded video' //[screenCaptureView playVideo:outputPathOrNil parent:self]; // Uncommented the following line to 'remove local copy of video' //[screenCaptureView removeLocalCopyOfVideo:outputPathOrNil]; // End other options
// notify user of video being created with/without audio... NSString * _msg = nil; if (includeAudio) _msg = [NSString stringWithFormat:@"The screen recording has completed and the video with audio has been saved to %@", outputName]; else _msg = [NSString stringWithFormat:@"The screen recording has completed and the video with no audio has been saved to %@", outputName]; if (includeAudio) _msg = @"The screen recording has completed and the video with audio has been saved to your Photos."; else _msg = @"The screen recording has completed and the video with no audio has been saved to your Photos."; [[[UIAlertView alloc] initWithTitle:@"Recording Completed" message:_msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];

// outputURL is nil so error occurred! } else {

// notify user of error recording the video! if (includeAudio) [[[UIAlertView alloc] initWithTitle:@"Error Recording Screen" message:@"The screen recording has stopped and the video with audio was not saved successfully to your Photos!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show]; else [[[UIAlertView alloc] initWithTitle:@"Error Recording Screen" message:@"The screen recording has stopped and the video with no audio was not saved successfully to your Photos!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show]; } }
// callback received when an asset (photo, video etc...) is saved to photos
// check error for if was sucessful or not
- (void)assetURL:(NSURL *)assetURL error:(NSError *)error {
NSLog(@"recording assetURL: %@ error: %@", assetURL, error); }

Some Benefits

  • Take a screen snapshot and save to photos.    Includes UIView and it's subviews contents.
  • Create a video of your app
  • Create a video of a specific view in your app.
  • Create a video and include audio for global sounds such as app sounds, mic etc....
  • Create a video including full screen device area and status area.
  • Create a video including full screen device area and no status area.
  • Add screen capture video recording capability to any view in your app
  • Make the main view for your app to allow your app users to create videos on their own
  • Create screen snapshot images. Can access the individual screen capture images used to create the video.
  • Create screen snapshot. Periodically samples its current display to create a snapshot of the screen. So you do not have to even start recording to get screen snapshots. Use frameRate to adjust the sampling rate.
  • Create full-screen screen capture or video with or without the status area.
  • Get a screen capture of full screen with status area.
  • Get a screen capture of the full screen without status area.
  • Get a screen capture of a specific view.

New alternative methods that do not require adding UIScreenCaptureView as main view.
e.g.: [screenCaptureView startRecordingViewForTimePeriod:seconds view:self.view parent:self];

New static screenshot methods for just getting a screenshot image for an area of the screen.

Use UIScreenCaptureView like any UIView class and add views to record as subviews. If you would like to use the class to make a video of your app, make a UIScreenCaptureView the main view for your app. This way the recording will include all views in your app.

If you want to record a specific view only, then replace the view to record with a UIScreenCaptureView instance.

UIScreenCaptureView will make a recording of anything in it's subviews. Powerful and simple including audio, if desired.

It's tested and works well on iOS7, iOS8,  iOS9 and iOS10.

3.8
  • 5 3
  • 4 0
  • 3 2
  • 2 1
  • 1 0
6 Reviews Read Reviews

Pricing

14 day 14-day money-back guarantee

$9.99

Single App

  • Perpetual license

  • 1 application

  • Can distribute binary products only

  • Commercial use

  • 1 month support

$29.99

Developer

  • Perpetual license

  • Unlimited projects

  • Can distribute code and binary products

  • Commercial use

  • 12 months support

Supported OS & SDK Versions

  • ARC, iOS8+
  • Supported build target - iOS7, iOS8, iOS9 and iOS10 / Mac OS 10.7 (Xcode 4.3.1, Apple LLVM compiler 3.1)
  • Earliest supported deployment target - iOS 6.1 / Mac OS 10.6
  • Earliest compatible deployment target - iOS 6.1 / Mac OS 10.6

NOTE: 'Supported' means that the library has been tested with this version. 'Compatible' means that the library should work on this OS version (i.e. it doesn't rely on any unavailable SDK features) but is no longer being tested for compatibility and may require tweaking or bug fixes to run correctly.

Installation

To install UIScreenCaptureView into your app, create a group named UIScreenCaptureView within your app project then drag the files from the ScreenCaptureView folder into the folder. Make sure that you indicate to copy the files into your project and set the target ownership of your app for all files copied.

You should copy these files:

  • ComOpenThreadOTScreenshotHelperSwizzleHelper.h
  • ComOpenThreadOTScreenshotHelperSwizzleHelper.m
  • IPAddress.h
  • IPAddress.c
  • OTScreenshotHelper.h
  • OTScreenshotHelper.m
  • SystemUtilities.h
  • SystemUtiities.m
  • UIDevice+Resolutions.h
  • UIDevice+Resolutions.m
  • UIScreenCaptureView.h
  • UIScreenCaptureView.m
  • UIView+ComOpenThreadOTScreenshotHelperStatusBar.h
  • UIView+ComOpenThreadOTScreenshotHelperStatusBar.m

Usage

To use this class, you must link against the following frameworks:

  - AssetsLibrary
  - AVFoundation
  - CoreGraphics
  - CoreMedia
  - CoreVideo
  - QuartzCore
  - MediaPlayer

// see Demo Example in Examples/Demo folder for full example and source code

 // To use view to make a video of screen snapshots of you app.
 // First make your view the UIScreenCaptureView
 // then any view added to UIScreenCaptureView will included when recording…


  (void)viewDidLoad {
 [super viewDidLoad];

 // create screen capture view.   Any subviews added to screen capture view will be recorded.
 BOOL recordFullscreen = FALSE;    // turn on to capture fullscreen, otherwise view only
 BOOL recordStatusBar = FALSE;    // turn on to include status bar when capturing fullscreen
 BOOL recordAudio = FALSE;    // turn on to include audio for system sounds (app, mic, etc..)
 
UIScreenCaptureView * screenCaptureView = [[UIScreenCaptureView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] fullscreen:recordFullscreen includeStatusBar:recordStatusBar]; [screenCaptureView includeAudio:recordAudio]; // indicates whether to include audio or not [screenCaptureView setVerbose:verbose]; // verbose debug mode on/off screenCaptureView.delegate = self; // implements UIScreenCaptureViewDelegate interface self.view = screenCaptureView; // add your views to be recorded. If you do not want to make the screenCaptureView your main view, see ALTERNATIVE below [self.view addSubView:yourView]; // set some options [screenCaptureView setFrameRate:10.0f]; // 10 frames per seconds (10 frames is the default) adjust to control // sampling of screen captures used in making video. [screenCaptureView setOutputName:@"output1.mp4"]; // output name (output.mp4 is the default) [screenCaptureView setVerbose:false]; // verbose debug mode (false is default) // ALTERNATIVE: if you did not want to set a UIScreenCaptureView as your parent view, then you // can use this alternate recording method to record your main views components. // To use this method you do not need to do the [self.view addSubview:yourView] call above // as you will be providing self.view which is your current view used. // [screenCaptureView startRecordingViewForTimePeriod:seconds view:self.view parent:self]; // MANUAL RECORDING TIED TO BUTTONS if you want manual start recording by clicking a button, // then create a UIButton that calls startRecording method when clicked. Add another button // to call stopRecording // TIMED RECORDING: this test shows starting a timed recording for 20 seconds which records // a video of view added to screenCaptureView [NSThread detachNewThreadSelector:@selector(startRecordingForTimePeriodTestThread:) toTarget:self withObject:@""]; // can also use static methods to get a screen capture image // // fullscreen shot with no status bar UIImage * screenSnapshot = [UIScreenCaptureView takeScreenSnapshot]; NSLog(@"screenSnapshot is width %.0f X height %.0f", screenSnapshot.size.width, screenSnapshot.size.height); // fullscreen shot with status bar UIImage * screenSnapshotWithStatusBar = [UIScreenCaptureView takeScreenSnapshotWithStatusBar]; NSLog(@"screenSnapshot with status bar is width %.0f X height %.0f", screenSnapshotWithStatusBar.size.width, screenSnapshotWithStatusBar.size.height); // fullscreen shot with no status bar UIImage * screenSnapshotWithNoStatusBar = [UIScreenCaptureView takeScreenSnapshotWithNoStatusBar]; NSLog(@"screenSnapshot with no status bar is width %.0f X height %.0f", screenSnapshotWithNoStatusBar.size.width, screenSnapshotWithNoStatusBar.size.height); // screenshot of a view... UIImage * screenSnapshotOfView = [UIScreenCaptureView takeScreenSnapshotOfView:self.view]; NSLog(@"screenSnapshot of view is width %.0f X height %.0f", screenSnapshotOfView.size.width, screenSnapshotOfView.size.height); } // timed recording... (void)startRecordingForTimePeriodTestThread:(NSString *)arg { [NSThread sleepForTimeInterval:1]; [self performSelectorOnMainThread:@selector(startRecordingForTimePeriodTest:) withObject:@"" waitUntilDone:NO]; } (void)startRecordingForTimePeriodTest:(NSString *)arg { [self startRecordingForTimePeriod:20]; } (void)startRecordingForTimePeriod:(int)seconds { recordButton.hidden = TRUE; stopButton.hidden = TRUE; playIndex = 0; recordingSeconds = seconds; recordingTimer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(recordingTimerElapsed:) userInfo:nil repeats:YES]; [screenCaptureView setFrameRate:10.0f]; // 10 frames per seconds (10 frames is the default) [screenCaptureView setOutputName:@"video.mp4"]; // output name (output.mp4 is the default) [screenCaptureView setVerbose:FALSE]; // verbose debug mode off // record any subview of screenCaptureView... //[screenCaptureView startRecordingForTimePeriod:seconds]; // record for N seconds // if you did not want to add a UIScreenCaptureView as your parent view, then you // can use this alternate recording method to record your main views components. // alternate method records any subview of self.view without having to // make screenCaptureView the parent view. Make sure the view passed is the main app view... // this is useful for adding app demo video recording to your app without modifying your view layout... [screenCaptureView startRecordingViewForTimePeriod:seconds view:self.view parent:self]; } (void)startRecording { recordButton.hidden = TRUE; stopButton.hidden = FALSE; playIndex = 0; recordingTimer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(recordingTimerElapsed:) userInfo:nil repeats:YES]; [screenCaptureView setFrameRate:10.0f]; // 10 frames per seconds (10 frames is the default) [screenCaptureView setOutputName:@"video.mp4"]; // output name (output.mp4 is the default) [screenCaptureView setVerbose:FALSE]; // verbose debug mode off [screenCaptureView startRecording]; // verbose debug mode (false is default) } // outputPathOrNil has the local output path if successful or nil if an error occurred... (void)recordingFinished:(NSURL *)outputPathOrNil { if (outputPathOrNil != nil) { NSLog(@"local output filename is %@", outputPathOrNil); // save the created video to Photos... NSString * outputName = [outputPathOrNil path]; [screenCaptureView saveToPhotos:outputName target:self]; // ---- other options: // play recorded video // [screenCaptureView playVideo:outputPathOrNil parent:self]; // remove local copy // [screenCaptureView removeLocalCopyOfVideo:outputPathOrNil]; // ---- end other options } else NSLog(@"Error creating the video!"); } (void)video:(NSString *)videoPath didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo { if (error != nil) NSLog(@"Try to saved video and got the error: %@", [error description]); } // Constructors: (id)initWithFrame:(CGRect)frame parent:(UIViewController *)parent; (id)initWithFrame:(CGRect)frame parent:(UIViewController *)parent fullscreen:(BOOL)_fullScreen includeStatusBar:(BOOL)includeStatusBar; // Static Methods: (UIImage *)takeScreenSnapshot;
[UIImage *)takeScreenSnapshotAndSave; (UIImage *)takeScreenSnapshotWithStatusBar; (UIImage *)takeScreenSnapshotWithNoStatusBar; (UIImage *)takeScreenSnapshotOfView:(UIView *)view; // Methods: (BOOL)startRecording; // start recording screen captures... (BOOL)startRecordingForTimePeriod:(int)seconds; // start recording screen captures for so many seconds... (BOOL)startRecordingView:(UIView *)view parent:(UIViewController *)_parent; // start recording screen captures for a view... (BOOL)startRecordingViewForTimePeriod:(int)seconds view:(UIView *)view parent:(UIViewController *)_parent; // start recording screen captures for so many seconds for a view... (void)stopRecording; // stop recording screen captures and save video... (UIImage *)screenCaptureView:(UIView *)view; // get screen capture image for a view (UIImage *)screenCaptureView2:(UIView *)view rect:(CGRect)rect; // get screen capture image for a specific area of a view (UIImage *)getCurrentScreenshot; (UIImage *)getScreenshotForView:(UIView *)view; (UIImage *)getImageForView:(UIView *)view usePresentationLayer:(BOOL)usePresentationLayer; (void)playVideo:(NSURL *)videoUrl parent:(UIViewController *)parent; // play a recorded view using the supplied view controller (BOOL)removeLocalCopyOfVideo:(NSURL *)localFile; // remove the local copy of a recorded video (void)setVerbose:(BOOL)verbose; // turn verbose mode on which displays more details when recording

Example Project Demo

The UIScreenCaptureViewDemo demo example in the Examples/Demo folder demonstrates how you might implement using UIScreenCaptureView.

The example is for iOS.

Additional Information

3 licenses, starting from From » $9.99 View Licenses

Get A Quote

What do you need?
  • Custom development
  • Integration
  • Customization / Reskinning
  • Consultation
When do you need it?
  • Soon
  • Next week
  • Next month
  • Anytime

Thanks for getting in touch!

Your quote details have been received and we'll get back to you soon.


Or enter your name and Email
  • FL Frank LaRosa 2 weeks ago
    My app produces sound using an AVAudioEngine. Will it capture this audio?
  • OM Ofir Malachi License holderSingle App
    1 month support
    Purchased on Jun 20, 2017
    1 month ago
    Will it record the AVCamera Layer?
  • YK Yannis Karampelas License holderSingle App
    6 month support
    Purchased on Mar 25, 2017
    4 months ago
    Will it record the keyboard and the activity on it?