简体   繁体   中英

RPBroadcastSampleHandler any method not getting called

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?

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.

I faced the same issue when I override the method - (void)beginRequestWithExtensionContext:(nonnull NSExtensionContext *)context { [self initScreenBroadcast]; } - (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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM