问题
I am using following code to record screen. It is working fine for ios10 and 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")
}
}
I can see Prompt for permission in ios10 and ios9 but not for ios11
ios11 Completion ( closure) block never calls
I have already verified that method calls correctly if condition if RPScreenRecorder.shared().isAvailable {
Also allows to let in
Please help me if anyone know about it
回答1:
I had the same problem as you, so I thinked in updating to iOS 11.0.2 and it worked for me! Hope it help you too.
Just in case, here are my methods:
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)
}
}
}
}
Methods of 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()
}
}
来源:https://stackoverflow.com/questions/46541509/replay-kit-not-working-ipad-ios11-bug