ReplayKit - finishBroadcastWithError not working

I have in my application Broadcast Upload extension. In broadcastStarted method I would like to, check does user is logged into my app. I've found how to do it in Apple WWDC presentation, but this resolve not works. Application does not streaming, but status bar showing that App still streaming. Here is my code:


override func broadcastStarted(withSetupInfo setupInfo: [String : NSObject]?) {
        // User has requested to start the broadcast. Setup info from the UI extension can be supplied but optional.
        let condition = false
        if(condition){
            Uploader.startBroadcast(to: "demoChannel1")
        }
        else{
                let userInfo = [NSLocalizedFailureReasonErrorKey: "Not Logged In"]
               let error = NSError(domain: "RPBroadcastErrorDomain", code: 401, userInfo: userInfo)
                super.finishBroadcastWithError(error)
               print("test")
        }


In my console i can see output "test" so it goes in correct if condition.

Thanks for any help

Replies

I met that situation. So i understood that broadcast-extension terminated earlier than system alert will be appeared. please check my solution:
1 - create property of SampleHandler
Code Block
private var startedWithError: BroadcastError? = nil

2 - set this error in streamStarted method
Code Block
override func broadcastStarted(withSetupInfo setupInfo: [String : NSObject]?) {
    guard let streamingSession = streamingSession else {
      startedWithError = .failedInitStreamingService
      return
    }
// some success code here
}

3 - check error in processSampleBuffer
Code Block
   override func processSampleBuffer(_ sampleBuffer: CMSampleBuffer, with sampleBufferType: RPSampleBufferType) {
     
    if let error = startedWithError {
      finishBroadcastWithError(error.nsError)
    }


P.S. Also you can use DispatchQueue.global.asyncAfter(.now()+0.5){ self.finishBroadcastWithError(error.nsError) } in broadcastStarted