ReplayKit RPBroadcastActivityViewController不可见iPhone

时间:2019-04-15 12:07:29

标签: ios uiviewcontroller uipickerview uiactivityviewcontroller replaykit

我正在尝试使用广播扩展程序从我的应用中进行流式传输。问题是RPBroadcastActivityViewController似乎不起作用。当我显示它时,我会弹出一个对话框,询问“ AppName是否想流传输到BroadcastExtensionSetupUI”,而不是我期望的选择器视图。之后,如果我查看viewDebugger,我看到RPBroadcastActivityViewController在顶部但100%透明,则delegate的{​​{1}}从未被调用,并且应用程序似乎冻结了。请注意,如果我从控制中心的apples ui开始,则可以流式播放。

UIActivityViewController

这是通过一个帮助类传递的,该帮助类传递了应该显示 var accessToken : String @objc public init(accessToken : String) { self.accessToken = accessToken super.init() RPScreenRecorder.shared().delegate = self NotificationCenter.default.addObserver(forName: UIScreen.capturedDidChangeNotification, object: UIScreen.main, queue: OperationQueue.main) { (notification) in if self.broadcastPickerView != nil && self.screenTrack == nil { //let isCaptured = UIScreen.main.isCaptured } } } deinit { NotificationCenter.default.removeObserver(self) } @available(iOS 12.0, *) func setupPickerView(view : UIView) { // Swap the button for an RPSystemBroadcastPickerView. #if !targetEnvironment(simulator) let pickerView = RPSystemBroadcastPickerView(frame: CGRect(x: 0, y: 0, width: view.bounds.width, height: 80)) pickerView.translatesAutoresizingMaskIntoConstraints = false pickerView.preferredExtension = TLScreenSharingHelper.kBroadcastExtensionBundleId // Theme the picker view to match the white that we want. if let button = pickerView.subviews.first as? UIButton { button.imageView?.tintColor = UIColor.white } view.addSubview(pickerView) self.broadcastPickerView = pickerView let centerX = NSLayoutConstraint(item:pickerView, attribute: NSLayoutConstraint.Attribute.centerX, relatedBy: NSLayoutConstraint.Relation.equal, toItem: view, attribute: NSLayoutConstraint.Attribute.centerX, multiplier: 1, constant: 0); view.addConstraint(centerX) let centerY = NSLayoutConstraint(item: pickerView, attribute: NSLayoutConstraint.Attribute.centerY, relatedBy: NSLayoutConstraint.Relation.equal, toItem: view, attribute: NSLayoutConstraint.Attribute.centerY, multiplier: 1, constant: -10); view.addConstraint(centerY) let width = NSLayoutConstraint(item: pickerView, attribute: NSLayoutConstraint.Attribute.width, relatedBy: NSLayoutConstraint.Relation.equal, toItem: view, attribute: NSLayoutConstraint.Attribute.width, multiplier: 0.75, constant: 0); view.addConstraint(width) let height = NSLayoutConstraint(item: pickerView, attribute: NSLayoutConstraint.Attribute.height, relatedBy: NSLayoutConstraint.Relation.equal, toItem: view, attribute: NSLayoutConstraint.Attribute.height, multiplier: 0.75, constant: 0); view.addConstraint(height) #endif } //MARK: Start screen share entry point @objc public func startScreenBroadcast(fromViewController vc: UIViewController) { // Use RPSystemBroadcastPickerView when available (iOS 12+ devices). if #available(iOS 12.0, *) { self.setupPickerView(view:vc.view) } //set token for the extension to use let sharedUserDefaults = UserDefaults(suiteName: kSharedUserDefaultsKey) sharedUserDefaults?.set(accessToken, forKey: kSharedUserDefaultsAccessTokenKey) sharedUserDefaults?.synchronize() if let controller = self.broadcastController { controller.finishBroadcast { [unowned self] error in DispatchQueue.main.async { self.broadcastController = nil } } } else { // This extension should be the broadcast upload extension UI, not broadcast update extension RPBroadcastActivityViewController.load(withPreferredExtension:TLScreenSharingHelper.kBroadcastExtensionSetupUiBundleId) { (broadcastActivityViewController, error) in if let broadcastActivityViewController = broadcastActivityViewController { broadcastActivityViewController.delegate = self broadcastActivityViewController.modalPresentationStyle = .popover vc.present(broadcastActivityViewController, animated: true) } } } } //MARK: RPBroadcastActivityViewControllerDelegate public func broadcastActivityViewController(_ broadcastActivityViewController: RPBroadcastActivityViewController, didFinishWith broadcastController: RPBroadcastController?, error: Error?) { DispatchQueue.main.async { self.broadcastController = broadcastController self.broadcastController?.delegate = self broadcastActivityViewController.dismiss(animated: true) { self.startBroadcast() } } } func startBroadcast() { self.broadcastController?.startBroadcast { error in DispatchQueue.main.async { if let theError = error { print("Broadcast controller failed to start with error:", theError as Any) } else { print("Broadcast controller started.") } } } } 的{​​{1}}。

为什么这个UIViewController是透明的?

0 个答案:

没有答案