IOS9 ReplayKit Video Recording
IOS9 ReplayKit video recording, the api is very simple, the following is the code, Objective-C is similar, it will not be written.
/// ReplayKitProxy. swift // ReplayKitDemo /// Created by LiuYanghui on 15/12/11. // Copyright? 2015 LiuYanghui. All rights reserved. // import UIKitimport ReplayKitclass ReplayKitProxy: NSObject, RPPreviewViewControllerDelegate {private var rootViewController: UIViewController? Private var previewViewController: RPPreviewViewController? Class var sharedInstance: ReplayKitProxy {struct Static {static var onceToken: dispatch_once_t = 0 static var instance: ReplayKitProxy? = Nil} dispatch_once (& Static. onceToken) {Static. instance = ReplayKitProxy () Static. instance ?. InitData ()} return Static. instance!} Private func initData () {}// start recording video func startRecording () {let recorder = RPScreenRecorder. sharedRecorder () if recorder. available = false {print ("Replaykit is not available") return} if recorder. recording = true {print ("Replaykit is recording") return} recorder. startRecordingWithMicrophoneEnabled (true) {(error)-> Void in if error! = Nil {print (error ?. LocalizedDescription) }}// stop the recording video func stopRecording () {let recorder = RPScreenRecorder. sharedRecorder () if recorder. recording = false {return} recorder. stopRecordingWithHandler {(previewViewController, error)-> Void in if error! = Nil {print (error ?. LocalizedDescription)} else if let viewController = previewViewController {viewController. previewControllerDelegate = self. previewViewController = viewController }}// deletes a recorded video. You must call func discardRecording () {let recorder = RPScreenRecorder after stopRecording. sharedRecorder () if recorder. recording = true {return} recorder. discardRecordingWithHandler {()-> Void in print ("discardRecording co Mplete ") }}// display the video func displayRecordingContent () {rootViewController ?. PresentViewController (self. previewViewController !, Animated: true, completion: {()-> Void in print ("display complete")} // MARK:-delegate func previewControllerDidFinish (previewController: rppreviewviewviewcontroller) {previewController. dismissViewControllerAnimated (true) {()-> Void in }}}