问题
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?
回答1:
I assume when you start recording red banner show on top of your screen. If you are expecting to debug extention when you run your build don't expect that.
You need to add your extention manually from XCode->Debug->Attach to Process by PID or Name. Once you click that Select you extention from there and then you will have your extension debugger.
I hope this will help you.
回答2:
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.
来源:https://stackoverflow.com/questions/59681554/rpbroadcastsamplehandler-any-method-not-getting-called