4

I'm currently working on live screen broadcasting app which allows the user's to share their screen on Youtube, Facebook, Mobcrush like apps. Everything is working fine but sometimes broadcast automatically getting stopped and throwing below error, and every time I open the app and after presenting RPBroadcastActivityViewController and after selecting the app, live preview view of the selected app is dismissed automatically and also RPBroadcastActivityViewController getting dismissed. Also, I can't able to enable the microphone. If I enable microphone it's throwing an error.

Error when broadcast automatically getting stopped -

Attempted to start an invalid broadcast session

Error when I try to enable microphone -

Microphone recording must be enabled first prior to startRecording

My code :-

extension MainViewController: RPBroadcastActivityViewControllerDelegate {
    func broadcastActivityViewController(_ broadcastActivityViewController: RPBroadcastActivityViewController, didFinishWith broadcastController: RPBroadcastController?, error: Error?) {
        broadCastVC = broadcastController
        broadCastVC?.delegate = self

        broadcastActivityViewController.dismiss(animated: true) {
            guard error == nil else {
                return
            }

            broadCastVC?.startBroadcast(handler: { (error) in
                RPScreenRecorder.shared().delegate = self
                RPScreenRecorder.shared().isMicrophoneEnabled = true
                guard error != nil else {
                    return
                }
                print(stringVal: "Live :- Error:- \(error?.localizedDescription ?? "")")
            })
        }
    }
}


extension MainViewController: RPBroadcastControllerDelegate {
    func broadcastController(_ broadcastController: RPBroadcastController, didFinishWithError error: Error?) {
        guard error != nil else {
            return
        }
        print(stringVal: "Live :- Error while starting broadcast :- \(error?.localizedDescription ?? "")")

        if broadCastVC?.isBroadcasting == true {
            broadCastVC?.finishBroadcast(handler: { (error) in
            })
        }
    }
}

extension MainViewController: RPScreenRecorderDelegate { }


extension MainViewController {

    @IBAction func switchAudio(_ sender: Any) {
        let sharedRecorder = RPScreenRecorder.shared()
        sharedRecorder.isMicrophoneEnabled = self.audioSwitch.isOn
    }

    @IBAction func btnStartBroadCastAction(_ sender: UIButton) {
        if broadCastVC?.isBroadcasting == true {
            broadCastVC?.finishBroadcast(handler: { (error) in
            })
        } else {
            RPBroadcastActivityViewController.load(handler: { (broadCastACTVC, error) in
                if let broadcastAVC = broadCastACTVC {
                    broadcastAVC.delegate = self

                    if UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.phone {
                        self.present(broadcastAVC, animated: true, completion: nil)
                    } else {
                        broadcastAVC.popoverPresentationController?.sourceView = self.btnBroadCast
                        broadcastAVC.modalPresentationStyle = UIModalPresentationStyle.formSheet
                        broadcastAVC.preferredContentSize = CGSize(width: self.view.frame.width, height: self.view.frame.height)
                        self.present(broadcastAVC, animated: true, completion: nil)
                    }
                }
            })
        }
    }
}

I can't able to find any document of ReplayKit. Please help me to find ReplayKit documents or any example if available.

Thank you.

Vikram Chaudhary
  • 580
  • 4
  • 14
  • any update on this? I got the same error "Attempted to start invalid..." when I try to stop the extension with finishBroadcastWithError. I set message to "Recording Stopped" but instead i got message "Attempted to start..." – peco Mar 18 '20 at 10:23
  • 1
    I tried a lot to get rid but I didn't get any hint or solution. So Instead of this, I used APIs of youtube and Facebook for live stream. – Vikram Chaudhary Mar 18 '20 at 18:05
  • I'm stuck on the same. Anyone got anything ? – Vivek Kumar Apr 20 '20 at 11:45
  • I think it may be an iOS issue because it's working fine on iOS 12. If anyone gets this working then please post the solution here. – Vikram Chaudhary Apr 21 '20 at 05:23

2 Answers2

0

This means your extension is crashing before setup completes. Use menu Debug > Attach to Process by PID or Name…, enter the exact name of your extension process, wait for it to be setup (it should appear under the debug inspector), and THEN start your broadcast session. You'll then find your crash in your debugger.

nevyn
  • 7,052
  • 3
  • 32
  • 43
0

You should check if your extension has exceed the memory limit of 50mb. In my case, I find that typing rapidly is the cause of the memory warning.

There are some discussions on Apple Developer Forums here talking about the memory issue, but no official reply so far.

David Lee
  • 74
  • 8