我正在使用以下代码记录屏幕。对于 ios10 和 ios9 正常工作
@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")
}
}
我可以在 ios10 和 ios9 中看到提示许可的提示,但没有 ios11 的提示
ios11 完成(关闭)块永远不会调用
我已经验证了如果条件
if RPScreenRecorder.shared().isAvailable {
也允许该方法正确调用该方法如果有人知道,请帮助我
最佳答案
我遇到了与您相同的问题,因此我考虑将其更新为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()
}
}
关于ios - 重播工具包不起作用IPAD IOS11 BUG,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46541509/