如何将ReplayKit添加到单个场景SpriteKit应用程序

时间:2015-12-18 15:09:08

标签: ios

使用此代码示例将ReplayKit添加到“单视图”iOS应用程序并重新编码和随后发送的视频都运行良好是微不足道的。我如何在单个场景SpriteKit应用程序中实现此功能?

import ReplayKit
import UIKit

class ViewController: UIViewController, RPPreviewViewControllerDelegate {
    override func viewDidLoad() {
        super.viewDidLoad()

        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Start", style: .Plain, target: self, action: "startRecording")
    }

    func startRecording() {
        let recorder = RPScreenRecorder.sharedRecorder()

        recorder.startRecordingWithMicrophoneEnabled(true) { [unowned self] (error) in
            if let unwrappedError = error {
                print(unwrappedError.localizedDescription)
            } else {
                self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Stop", style: .Plain, target: self, action: "stopRecording")
            }
        }
    }

    func stopRecording() {
        let recorder = RPScreenRecorder.sharedRecorder()

        recorder.stopRecordingWithHandler { [unowned self] (preview, error) in
            self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Start", style: .Plain, target: self, action: "startRecording")

            if let unwrappedPreview = preview {
                unwrappedPreview.previewControllerDelegate = self
                self.presentViewController(unwrappedPreview, animated: true, completion: nil)
            }
        }
    }

    func previewControllerDidFinish(previewController: RPPreviewViewController) {
        dismissViewControllerAnimated(true, completion: nil)
    }
}

0 个答案:

没有答案