How to detect when RPSystemBroadcastPickerView is dismissed?

2.3k views Asked by At

In the app, I am using a RPSystemBroadcastPickerView to start a system-wide screen recording. I need to react to the user starting screen record or dismissing the shown picker view. In both cases, the system view gets dismissed.

I assumed that dismissing the system picker view will trigger a viewDidAppear event on the currently shown view controller. This does not happen. I tried to test if the AppDelegate triggers applicationDidBecomeActive or applicationWillEnterForeground - again without success (this are triggered when user open control center).

Does anyone have a suggestion what else to try?

2

There are 2 answers

2
CoderWGB On

Before iOS 13: hook RPSystemBroadcastPickerView containerVC

iOS 14.0 or later: Monitor the focus and out-focus events of the app

2
Jeeva On

You can achieve it indirectly using Timer and UserDefaults.

Start the Timer in ViewController from the main app and check for corresponding value change from Broadcast Extension.

 class SampleHandler: RPBroadcastSampleHandler {

    override func broadcastStarted(withSetupInfo setupInfo: [String : NSObject]?) {
       appGroupDefaults.set(true, forKey: appGroupUserDefaultKeys.isScreenBroadcastStarted.rawValue)
    }

    override func broadcastFinished() {
       appGroupDefaults.set(true, forKey: appGroupUserDefaultKeys.isScreenBroadcastStopped.rawValue)
    }
    
 }