ReplayKit:永远不会输入startRecording()完成处理程序 [英] ReplayKit: startRecording() completion handler is never entered
问题描述
问题描述
即使显示了允许$ AppName中的屏幕录像"弹出窗口,也永远不会输入startRecording()完成处理程序.有时会显示允许$ AppName中的屏幕录像"弹出窗口.当我删除应用程序,重新启动设备并在项目上进行清理/构建时,也会发生这种情况.我正在使用具有iOS 11和Xcode 9的iPad Air 2.
The startRecording() completion handler is never entered, even though the "Allow screen recording in $AppName" pop-up was shown. The "Allow screen recording in $AppName" pop-up is shown occasionally. This happens also when I remove the app, restart the device and do a clean/build on the project. I'm using an iPad Air 2 with iOS 11 and Xcode 9.
研究
此问题在早期版本中似乎也是一个问题,请参见此处: replaykit startrecording有时永远不会进入完成处理程序 我不赞成通过关闭WiFi或建立稳定的互联网连接来解决此问题,在iOS 11中也未解决此问题.
This problem seemed to be an issue in earlier versions as well, see here: replaykit startrecording sometimes never enters completion handler I can't approve that turning off WiFi or having a stable internet connection solves this problem, neither has this problem being fixed in iOS 11.
这是我正在使用的代码:
Here is the code I'm using:
@IBAction func recordButtonTapped(_ sender: UIButton) {
if !recorder.isRecording {
startRecording(sender)
} else {
stopRecording(sender)
}
}
private func startRecording(_ sender: UIButton) {
guard recorder.isAvailable else {
print("Recording is not available at this time.")
// Display UI for recording being unavailable
return
}
recorder.startRecording(handler: { (error) in
guard error == nil else {
print("There was an error starting the recording.")
print(error!)
return
}
print("Started Recording Successfully")
DispatchQueue.main.async {
sender.setTitle("Stop Recording", for: .normal)
sender.setTitleColor(.red, for: .normal)
}
})
}
推荐答案
我想我自己找到了答案.请尝试一下并确认是否可行:
I guess I found the answer myself. Please try this out and and confirm if it works:
- 删除您的应用
- 清理Xcode项目
- 按住iOS设备的电源按钮
- 出现要关闭的幻灯片时,按住主屏幕按钮,直到屏幕闪烁黑色,然后释放所有按钮
- 再次运行您的Xcode项目
- 现在应该再次调用处理程序
我怀疑记录器使用的共享实例中存在一些错误,这些错误只能在清理设备RAM时重置.
My suspicion is that there is some bug in the used shared instance of the recorder which can only be reset when cleaning up the device RAM.
修改: 我还观察到,仅在录制过程中停止使用Xcode运行的应用程序时,才会发生此错误.如果我将应用程序置于后台或使用iOS任务管理器关闭该应用程序,则在再次启动该应用程序时不会出现此错误.
I also observed that this error only happens when I stop the running app with Xcode while the recording is in progress. If I put the app in the background or shut down the app with the iOS task manager, then this error does not appear when the app is started again.
结论:请勿在录制运行时使用Xcode关闭您的应用.如果您改用iOS任务管理器,它将继续正常工作并提供回调.
Conclusion: DO NOT shut down your app using Xcode, while recording is running. If you use the iOS task manager instead then it will continue working properly and deliver the callbacks.
修改2: 提交了一个错误报告,Apple回答说他们知道此问题,并致力于解决该问题.
Edit 2: A bug report is filed and Apple answered that they are aware of this problem, working on it to solve it.
这篇关于ReplayKit:永远不会输入startRecording()完成处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!