-
-
Save markelsoft/36018c5233ba4a0488c5cdd157bd2155 to your computer and use it in GitHub Desktop.
Created a "Single View Application" project and added ReplayKit code to the ViewController files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.h | |
// ReplayKitExample | |
// | |
// Created by Christopher Stoll on 6/11/15. | |
// Copyright © 2015 Christopher Stoll. All rights reserved. | |
// | |
#import <UIKit/UIKit.h> | |
#import <ReplayKit/ReplayKit.h> | |
@interface ViewController : UIViewController <RPScreenRecorderDelegate, RPPreviewViewControllerDelegate> | |
@property (weak, nonatomic) RPPreviewViewController *previewViewController; | |
- (IBAction)doRecord:(id)sender; | |
- (IBAction)doPreviewSave:(id)sender; | |
@end | |
// | |
// ViewController.m | |
// ReplayKitExample | |
// | |
// Created by Christopher Stoll on 6/11/15. | |
// Copyright © 2015 Christopher Stoll. All rights reserved. | |
// | |
#import "ViewController.h" | |
@interface ViewController () | |
@end | |
@implementation ViewController | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
// Do any additional setup after loading the view, typically from a nib. | |
} | |
- (void)didReceiveMemoryWarning { | |
[super didReceiveMemoryWarning]; | |
// Dispose of any resources that can be recreated. | |
} | |
#pragma mark - ReplayKit | |
- (void)startScreenRecording { | |
RPScreenRecorder *sharedRecorder = RPScreenRecorder.sharedRecorder; | |
sharedRecorder.delegate = self; | |
[sharedRecorder startRecordingWithMicrophoneEnabled:YES handler:^(NSError *error) { | |
if (error) { | |
NSLog(@"startScreenRecording: %@", error.localizedDescription); | |
} | |
}]; | |
} | |
- (void)stopScreenRecording { | |
RPScreenRecorder *sharedRecorder = RPScreenRecorder.sharedRecorder; | |
[sharedRecorder stopRecordingWithHandler:^(RPPreviewViewController *previewViewController, NSError *error) { | |
if (error) { | |
NSLog(@"stopScreenRecording: %@", error.localizedDescription); | |
} | |
if (previewViewController) { | |
previewViewController.previewControllerDelegate = self; | |
self.previewViewController = previewViewController; | |
// RPPreviewViewController only supports full screen modal presentation. | |
self.previewViewController.modalPresentationStyle = UIModalPresentationFullScreen; | |
[self.view.window.rootViewController presentViewController:previewViewController animated:YES completion:nil]; | |
} | |
}]; | |
} | |
#pragma mark - RPScreenRecorderDelegate | |
- (void)screenRecorder:(RPScreenRecorder *)screenRecorder didStopRecordingWithError:(NSError *)error previewViewController:(nullable RPPreviewViewController *)previewViewController { | |
// handle error which caused unexpected stop of recording | |
} | |
- (void)screenRecorderDidChangeAvailability:(RPScreenRecorder *)screenRecorder { | |
// handle screen recorder availability changes | |
} | |
#pragma mark - RPPreviewViewControllerDelegate | |
- (void)previewControllerDidFinish:(RPPreviewViewController *)previewController { | |
[previewController dismissViewControllerAnimated:YES completion:nil]; | |
} | |
#pragma mark - Interface Actions | |
- (IBAction)doRecord:(id)sender { | |
[self startScreenRecording]; | |
} | |
- (IBAction)doPreviewSave:(id)sender { | |
[self stopScreenRecording]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment