Skip to content

Instantly share code, notes, and snippets.

@stollcri
Last active May 9, 2018 18:11
Show Gist options
  • Select an option

  • Save stollcri/732def91d09525deb49c to your computer and use it in GitHub Desktop.

Select an option

Save stollcri/732def91d09525deb49c to your computer and use it in GitHub Desktop.

Revisions

  1. stollcri renamed this gist Jun 12, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. stollcri created this gist Jun 12, 2015.
    107 changes: 107 additions & 0 deletions ReplayKitExample
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,107 @@
    //
    // 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