使用广播 UI 扩展显示 UI(可能是故事板)

Oll*_*lli 5 xcode ios swift replaykit

我对 IOS 编程有点陌生,我正在尝试使用 Replaykit 开始直播,我在从应用程序调用广播服务选择器视图以及创建 2 个扩展(广播上传扩展和广播)方面取得了一些进展用户界面扩展)。显然,一旦从选择器视图中选择了扩展程序,就应该加载广播 UI 扩展程序,而另一个在广播开始后接收数据,我已经尝试通过创建情节提要并为其提供一个自定义类来创建视图使用广播 UI 扩展,但是当我从选择器视图中单击扩展时,我立即收到错误The user declined application recording(不确定我是否遗漏了此处的任何步骤),在没有情节提要的情况下也会出现相同的错误,我尝试print()override func viewDidLoad() 的广播 UI 扩展视图控制器,并且在调试区域中没有日志,所以我什至不知道它是否被加载。

我需要的是显示简单的 UI,然后调用 Broadcast UI 扩展视图控制器函数 ( func userDidFinishSetup()),然后开始广播。如果广播可以在没有 UI 的情况下直接在应用程序中启动,我也会接受,在Replaykit 文档中,我看到一个startBroadcast我认为可以实现此目的的功能,出现broadcastInvalidSession = -5808错误,这意味着我“试图在没有事先会话的情况下启动广播” . 非常感谢帮助,谢谢。

广播 UI 视图控制器

import ReplayKit

class BroadcastSetupViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        print("WASSUP?");
    }

    // Call this method when the user has finished interacting with the view controller and a broadcast stream can start
    func userDidFinishSetup() {
        print("GET IN!!!");
        // URL of the resource where broadcast can be viewed that will be returned to the application
        let broadcastURL = URL(string:"http://apple.com/broadcast/streamID")

        // Dictionary with setup information that will be provided to broadcast extension when broadcast is started
        let setupInfo: [String : NSCoding & NSObjectProtocol] = ["broadcastName": "example" as NSCoding & NSObjectProtocol]

        // Tell ReplayKit that the extension is finished setting up and can begin broadcasting
        self.extensionContext?.completeRequest(withBroadcast: broadcastURL!, setupInfo: setupInfo)
    }

    func userDidCancelSetup() {
        let error = NSError(domain: "YouAppDomain", code: -1, userInfo: nil)
        // Tell ReplayKit that the extension was cancelled by the user
        self.extensionContext?.cancelRequest(withError: error)
    }
}

Run Code Online (Sandbox Code Playgroud)

Oll*_*lli 3

所以我联系了Apple技术支持事件(遗憾的是),他们建议我将“NSExtensionMainStoryboard”添加到广播UI扩展的info.plist中,类似于Greg的答案,当这不起作用时,我发送了我的代码,我们发现我还必须从阻止加载的同一位置删除“NSExtensionPrincipalClass”键,之后它工作正常。