Search code examples
iosreplaykit

how do you broadcast the iphone screen


There are a small number of iOS apps which can broadcast the entire iPhone screen (mirror the whole screen including the homescreen) -> Teamviewer, Microsoft Teams, RescueAssist. To do so the user will start the video recording and choose one of those apps as the broadcast receiver.

How do you write such an app? I have searched through the web and I did not find a detailed technical explanation what is required to do so.


Solution

  • As suggested you have to create a broadcast extension. That extension gives you the method calls which delivers the frames. Then you can stream the frames to the internet (e.g. Haishinkit).

    override func processSampleBuffer(_ sampleBuffer: CMSampleBuffer, with sampleBufferType: RPSampleBufferType) {
    
        switch sampleBufferType {
            case RPSampleBufferType.video:
                rtmpStream?.appendSampleBuffer(sampleBuffer, withType: AVMediaType.video)
    
                // Handle video sample buffer
                break
            case RPSampleBufferType.audioApp:
                // Handle audio sample buffer for app audio
                break
            case RPSampleBufferType.audioMic:
                // Handle audio sample buffer for mic audio
                break
        }
    }
    

    Note, that most likely Apple will decline your app. They only allow it for a few cases.