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?