我想实现像skype一样的屏幕共享功能(当应用程序在后台时,它也将共享iPhone的屏幕),为此,我使用广播扩展。
这是我在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
})
}
}当我点击RPSystemBroadcastPickerView时,弹出的是开始广播,而当我开始广播时,任何扩展方法都不会调用。
这是我的扩展类
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")
}
}
}你能帮我找出我做错了什么吗?
发布于 2020-01-20 21:13:26
您还可以选择并运行扩展(而不是iOS目标)。然后,XCode会询问你“选择一个要运行的应用程序”,并列出你设备上的所有应用程序。选择你的应用,然后点击"run“。
然后您的应用程序将启动,但您的扩展将被调试(断点将应用,打印将显示在输出控制台中),当您长按控制视图中的录制/广播按钮后,选择您的扩展并开始广播。
发布于 2020-02-10 22:33:23
当我重写- (void)beginRequestWithExtensionContext:(nonnull NSExtensionContext *)context { [self initScreenBroadcast]; }方法时,我遇到了同样的问题
我通过调用此方法的super解决了这个错误。
- (void)beginRequestWithExtensionContext:(nonnull NSExtensionContext *)context {
[super beginRequestWithExtensionContext:context];
[self initScreenBroadcast];}
注意:我没有使用带有广播上传扩展的广播UI扩展,所以我的扩展没有ui,因此从未调用过broadcastStartedWithSetupInfo方法。这在setupUI完成时调用。因此,我必须通过重写beginRequestWithExtensionContext来获取触发器
希望它能帮上忙!
发布于 2020-01-17 19:36:12
您需要从XCode->Debug->Attach to Process按PID或名称手动添加扩展。一旦你点击,选择你的扩展从那里,然后你就会有你的扩展调试器。
我希望这能对你有所帮助。
https://stackoverflow.com/questions/59681554
复制相似问题