如何在iPad上展示RPBroadcastActivityViewController。
我正在使用标准代码开始录制
RPBroadcastActivityViewController.load { [unowned self] (broadcastActivityViewController, error) in
// If an error has occurred, display an alert to the user.
if let error = error {
self.showAlert(message: error.localizedDescription)
return
}
// Present vc
if let broadcastActivityViewController = broadcastActivityViewController {
broadcastActivityViewController.delegate = self
// present
self.present(...
}
}
适用于iPhone,但在iPad上没有任何内容,应用程序也会冻结。我一直在查看使用此功能的应用程序商店的游戏,我注意到了同样的问题。
在游戏Tower Dash上按下iPad上的直播按钮时没有任何内容,它只适用于iPhone。
我一直在尝试使用popover演示文稿,但似乎没有任何效果。
我错过了什么吗?
更新:这似乎是一个错误。即使在苹果自己的Swift Playground应用程序中也会发生这种情况。
UPDATE2:Apple实际上已经回复了我的错误报告并告诉我,我需要在iPad上显示View Controller作为一个像这样的popover
UIDevice.current.userInterfaceIdiom == .pad {
broadcastAVC.popoverPresentationController?.sourceView = view
broadcastAVC.popoverPresentationController?.sourceRect = CGRect(x: view.bounds.midX, y: view.bounds.midY, width: 0, height: 0)
broadcastAVC.popoverPresentationController?.permittedArrowDirections = UIPopoverArrowDirection.init(rawValue: 0) // no arrow
}
然而它仍然不适合我。正如我所提到的,这发生在Apple自己的Swift Playground应用程序上,所以它一定是个bug。
修正:
我忘了在上面提到的代码中添加这一行
broadcastAVC.modalPresentationStyle = .popover
答案 0 :(得分:1)
Apple的演示应用程序不包含这些细节,这是正确的,但它不是一个错误。这就是我用它来在iPad上工作的原因。 iPad需要弹出窗口来呈现视图,而弹出框需要锚点。我选择将它锚定到leftBarButtonItem。
if let unwrappedPreview = preview {
unwrappedPreview.previewControllerDelegate = self
if UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.phone {
self.present(unwrappedPreview, animated: true, completion: nil)
}
else {
unwrappedPreview.popoverPresentationController?.barButtonItem = self.navigationItem.leftBarButtonItem!
unwrappedPreview.modalPresentationStyle = UIModalPresentationStyle.popover
unwrappedPreview.preferredContentSize = CGSize(width: self.view.frame.width, height: self.view.frame.height)
self.present(unwrappedPreview, animated: true, completion: nil)
}
}
答案 1 :(得分:0)
iOS 10.1 beta 2仍然存在同样的问题。
目前,我发现在iPad上呈现RPBroadcastActivityViewController
的唯一方法是将其呈现在特征集合的水平紧凑环境中。
因此,在选择支持广播的应用程序之前,您可能需要告诉用户切换到拆分视图模式,然后切换回全屏。返回全屏后,您可以使用RPBroadcastController.startBroadcast(handler:)
开始广播。