How to detect when the RPSystemBroadcastPickerView is tapped

4.1k views Asked by At

I am using RPSystemBroadcastPickerView to start a system-wide screen recording from my app. The RPSystemBroadcastPickerView is completely autonomous in starting the recording and everything, which I guess makes sense - only user can start the screen recording by explicitly tapping the button.

I need to know when the RPSystemBroadcastPickerView is tapped. Right now the UI is showing keyboard, which I want to keep showing (it is a chat app). However, the form showing the list of broadcast extensions to pick one is being shown under the keyboard. See following image:

enter image description here

This effectively prevents the user to start the broadcast. If I knew when the user tapped RPSystemBroadcastPickerView, I could manually hide the keyboard at that moment. Any suggestions?

2

There are 2 answers

3
Bws Sluk On BEST ANSWER

I did not find any callbacks for that, but you can create your transparent button, add it above the RPSystemBroadcastPickerView. When user will tap on your button you will be able to hide the keyboard and than transfer the action to the RPSystemBroadcastPickerView using the code:

for subview in screenSharingProviderPickerView.subviews {
    if let button = subview as? UIButton {
         button.sendActions(for: UIControlEvents.allTouchEvents)
    }
}
0
vpoltave On

I found similar solution to accepted answer, but you don't need to create transparent button.
I just add additional target-action pair to the picker button dispatch table, with #selector which will be fired, when button is pressed.

// picker is an instance of RPSystemBroadcastPickerView
for subview in picker.subviews {
    if let button = subview as? UIButton {
        button.addTarget(self, action: #selector(pickerAction), for: .touchUpInside)
    }
}

// You can also accept _ sender: UIButton as parameter, if you need to.
@objc func pickerAction() {
    // called when user press on RPSystemBroadcastPickerView
}

Note: Keep in mind that, if Apple change hierarchy of this view in the future, you probably need to update application as well.