iosswiftreplaykit

Display custom error message from iOS broadcasting extension


My application bundle consists of the main app (normal iOS application) and broadcasting extension (ReplayKit 2). My app contains a button (RPSystemBroadcastPickerView), which opens a system popup to select a broadcasting extension and start it.

The one does not have much control over the state of the broadcasting extension inside the extension, however the extension's class which inherits RPBroadcastSampleHandler has one useful method (finishBroadcastWithError), which allows us to trigger a fail from the extension (which will in turn end the extension's process and show a popup window, showing an error and 2 buttons).

The finishBroadcastWithError method accepts an error as an argument. However there is absolutely no information in docs how to customize the error message shown in this system popup window.

I tried to google in order to understand how to set an error message, because I saw some apps (Mobcrush), which somehow were able to set a custom error message when this popup appears. In order to get more info, I watched both videos about ReplayKit 2 from WWDC 2017 and WWDC 2018, the only slide which mentioned something about error handling in Replay Kit 2 was the one, where the following code was demonstrated:

let userInfo = [NSLocalizedFailureReasonErrorKey : "Not Logged In"]
let error = NSError(domain: "RPBroadcastErrorDomain", code: 401, userInfo: userInfo)
finishBroadcastWithError(error)

I tried it immediately, but unfortunately it does not have any effect on the error shown in the error popup. I assume that either it's some bug in Replay Kit 2 or that something has been changed and was not documented properly (for some reason Replay Kit 2 is not that well documented and I had to gather pieces of information from different sources to write an app which works).

I even tried setting multiple different keys in a dictionary, hoping that at least one of them will change the error message in a popup window, but none of them worked.

func stop(message error: String) {
    let userInfo = [NSLocalizedDescriptionKey : error,
                    NSLocalizedRecoverySuggestionErrorKey : error,
                    NSLocalizedFailureErrorKey : error]
    let error = NSError(domain: "RPBroadcastErrorDomain", code: 1, userInfo: userInfo)
    finishBroadcastWithError(error)
}

Did I miss something in docs? Is there any "official" way to change the error message?


Solution

  • I'm getting customized error with this set of parameters:

    let userInfo = [NSLocalizedFailureReasonErrorKey: "failed to broadcast because...."]
    NSError(domain: "ScreenShare", code: -1, userInfo: userInfo)