RPBroadcastSampleHandler any method not getting called
Asked Answered
T

3

7

I want to implement screen sharing functionality like skype(when app is in background then also it will share screen of iPhone), and for that i am using broadcast extension.

Here its my code in my viewcontroller.swift

    import UIKit
    import ReplayKit
    @available(iOS 12.0, *)
    class ViewController: UIViewController {

        var broadcastPicker: RPSystemBroadcastPickerView?
        var broadcastSession : NSObject?
        override func viewDidLoad() {
            super.viewDidLoad()
            let kPickerFrame = CGRect(x: 100.0, y: 100.0, width: 100.0, height: 100.0)
            broadcastPicker = RPSystemBroadcastPickerView(frame: kPickerFrame)
            broadcastPicker?.backgroundColor = UIColor.green
            broadcastPicker!.preferredExtension = "com.sharescreen.Recoder"
            view.addSubview(broadcastPicker!)

            extensionContext?.loadBroadcastingApplicationInfo(completion: {
            (bundleID, displayName, appIcon) in

            })

        }
   }

and when i click on RPSystemBroadcastPickerView i am getting popup for start broadcast and when i start broadcast any extension method is not calling.

This is my extension class

    class SampleHandler: RPBroadcastSampleHandler {


    var session : VTCompressionSession?
    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.

    }

    override func broadcastPaused() {
        // User has requested to pause the broadcast. Samples will stop being delivered.
    }

    override func broadcastResumed() {
        // User has requested to resume the broadcast. Samples delivery will resume.
    }

    override func broadcastFinished() {
        // User has requested to finish the broadcast.
    }

    override func processSampleBuffer(_ sampleBuffer: CMSampleBuffer, with sampleBufferType: RPSampleBufferType) {
        switch sampleBufferType {
        case RPSampleBufferType.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
        @unknown default:
            // Handle other sample buffer types
            fatalError("Unknown type of sample buffer")
        }
    }
}

Can you please help me to find out that what i am doing wrong?

Trapezius answered 10/1, 2020 at 12:19 Comment(0)
B
6

You could also select and run the extension (instead of the iOS target). XCode will then ask you "Choose an app to run" with a list of all apps on your device. Select your app and click "run".

Then your app will be started, but your extension will be debugged (breakpoints will apply and prints will be shown in the output console) after you long press the record/broadcast button in the control view, select your extension and start broadcasting.

Boracic answered 20/1, 2020 at 13:13 Comment(1)
Is there any way to invoke methods such as broadcastPaused / brodcastResumed programmatically ?Koan
P
1

I faced the same issue when I override the method - (void)beginRequestWithExtensionContext:(nonnull NSExtensionContext *)context { [self initScreenBroadcast]; }

I resolved the error by calling super of this method.

- (void)beginRequestWithExtensionContext:(nonnull NSExtensionContext *)context {
[super beginRequestWithExtensionContext:context];
[self initScreenBroadcast];

}

Note: I am not using a Broadcast UI extension with Broadcast upload Extension so my extension has no ui, due to which the method broadcastStartedWithSetupInfo was never called. This is called when the setupUI finishes. Hence I had to get the trigger by overriding beginRequestWithExtensionContext

Hope it helps!

Pasia answered 10/2, 2020 at 14:33 Comment(0)
L
0

You need to add your extention manually from XCode->Debug->Attach to Process by PID or Name. Once you click that Select your extension from there and then you will have your extension debugger.

I hope this will help you.

Linden answered 17/1, 2020 at 11:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.