2

我正在使用以下代码来记录屏幕。它适用于ios10ios9

 @IBAction func btnRecordTapped(_ sender: UIButton) {

    if RPScreenRecorder.shared().isAvailable {


        if #available(iOS 10.0, *) {
            RPScreenRecorder.shared().startRecording(handler: { (error) in
                guard error == nil else {
                    print("Record failed with error \(error!.localizedDescription)")
                    return
                }

                DispatchQueue.main.async {
                    sender.removeTarget(self, action: #selector(self.btnRecordTapped(_:)), for: .touchUpInside)
                    sender.addTarget(self, action: #selector(self.stoprecording(button:)), for: .touchUpInside)

                    sender.setTitle("Stop", for: .normal)
                    sender.setTitleColor(.red, for: .normal)


                }


            })
        } else {

            RPScreenRecorder.shared().startRecording(withMicrophoneEnabled: false, handler: { (error) in

                guard error == nil else {
                    print("Record failed with error \(error!.localizedDescription)")
                    return
                }

                DispatchQueue.main.async {
                    sender.removeTarget(self, action: #selector(self.btnRecordTapped(_:)), for: .touchUpInside)
                    sender.addTarget(self, action: #selector(self.stoprecording(button:)), for: .touchUpInside)

                    sender.setTitle("Stop", for: .normal)
                    sender.setTitleColor(.red, for: .normal)


                }

            })
        }
    } else {
        print("Screen Reocrder not availble")
    }

}

我可以在ios10ios9中看到提示权限, 但在ios11中看不到

ios11 完成(闭包)块从不调用
我已经验证了方法调用正确 if 条件 if RPScreenRecorder.shared().isAvailable {还允许让

如果有人知道,请帮助我

在此处输入图像描述

在此处输入图像描述

4

1 回答 1

2

我和你有同样的问题,所以我想更新到 iOS 11.0.2,它对我有用!希望对你也有帮助。

以防万一,这是我的方法:

let recorder = RPScreenRecorder.shared()

@IBAction func recordingAction(_ sender: Any) {
        if recorder.isRecording {
            stopRecordAction()
        } else {
            startRecordAction()
        }
}

func startRecordAction() {
     recorder.startRecording{ (error) in
            if let error = error {
               print("❗️",error)
             }
      }
}

func stopRecordAction() {
            recorder.stopRecording{ (previewVC, error) in
                if let previewVC = previewVC {
                    previewVC.previewControllerDelegate = self
                    self.present(previewVC, animated: true, completion: nil)
                    if let error = error {
                        print("❗️",error)
                    }
                }
            }
    }

RPPreviewViewControllerDelegate 的方法:

func previewControllerDidFinish(_ previewController: RPPreviewViewController) {
        dismiss(animated: true, completion: nil)
    }

    func previewController(_ previewController: RPPreviewViewController, didFinishWithActivityTypes activityTypes: Set<String>) {
        /// This path was obtained by printing the actiong captured in "activityTypes"
        if activityTypes.contains("com.apple.UIKit.activity.SaveToCameraRoll") {
            recordFinshedMessage()
        }
    }
于 2017-10-05T02:16:26.917 回答