Search code examples
iosreplaykit

How to programatically stop a ReplayKit 2 system broadcast without RPSystemBroadcastPickerView


I am trying to implement a broadcast upload extension and I want the user to be able to click a button in my app to stop the broadcast.

As far as I can tell from the docs, the only ways to stop a system broadcast are:

  • Show RPSystemBroadcastPickerView in the app, when the user clicks it, they are taken to the system UI and stop the broadcast there.
  • Signal the broadcast extension to stop via other means and call finishBroadcastWithError in RPBroadcastSampleHandler which will show the user an error popup. It's a trick that Zoom seems to use.

However, I was trying the screen sharing feature on Facebook Messenger today and they are somehow bypassing the system UI (to stop the stream only). When I click the stop button, the screen sharing stops immediately and doesn't show either the system UI or the error popup

How are they doing this? My best guess is that they somehow get a valid RPBroadcastController object but I can't figure out how.


Solution

  • Ended up figuring it out.

    You basically just need to pass nil to finishBroadcastWithError. It'll throw a warning because the error is not nullable but you can quiet it with this:

    #pragma clang diagnostic push
    #pragma clang diagnostic ignored "-Wnonnull"
        [self finishBroadcastWithError:nil];
    #pragma clang diagnostic pop