ReplayKit: startRecording() completion handler is never entered

旧巷老猫 提交于 2019-12-01 06:09:37

问题


Problem description

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.

Research

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)
        }
    })
}

回答1:


I guess I found the answer myself. Please try this out and and confirm if it works:

  1. Delete your App
  2. Clean Xcode project
  3. Hold power button of your iOS device
  4. When slide to turn off appears, hold home button until screen flashes black, then release all buttons
  5. Run your Xcode project again
  6. Handlers should now be called again

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.

Edit: 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.

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.

Edit 2: A bug report is filed and Apple answered that they are aware of this problem, working on it to solve it.



来源:https://stackoverflow.com/questions/46362015/replaykit-startrecording-completion-handler-is-never-entered

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!