5

I'm a bit new to IOS programming, I'm trying to start a live broadcast using Replaykit, I've made some progress in calling the broadcast service picker view from the App and also in creating 2 extensions (Broadcast Upload Extension and Broadcast UI extension). Apparently the Broadcast UI extension should be loaded once the extension is selected from the picker view and the other receives data once broadcast begins, I've tried in the first to create a view by creating a storyboard and giving it a custom class that's the same with that of the Broadcast UI extension however when I then click on the extension from the picker view I get the immediate error The user declined application recording (not sure if I'm missing any step here), get this same error without the storyboard too, I tried print() in override func viewDidLoad() of the Broadcast UI extension view controller and got no logs in the debug area so I don't even know if it gets loaded at all.

What I need is to display simple UI that'll then call a Broadcast UI extension view controller function (func userDidFinishSetup()) that'll then begin the broadcast. I'll also accept if the broadcast can be started directly within the App without the UI, in the Replaykit docs I saw a startBroadcast function I thought could achieve this, got a broadcastInvalidSession = -5808 error which means I "attempted to start a broadcast without a prior session". Help greatly appreciated, thanks.

Broadcast UI view controller

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)
    }
}

Olli
  • 512
  • 3
  • 6
  • 22
  • Does [this code](https://github.com/kaelhem/cordova-replay/blob/master/src/ios/CDVCordovaReplay.swift) help? – wizzwizz4 Feb 20 '19 at 14:03
  • Unfortunately not, that code just displays a view to pick broadcast service providers, does not instantiate broadcast from the App itself – Olli Feb 20 '19 at 14:15

2 Answers2

3

So I reached out to Apple technical support incident(regrettably), they suggested I add "NSExtensionMainStoryboard" to the info.plist of the broadcast UI extension similar to Greg's answer, when that didn't work I sent over my code and we found out that I also had to delete "NSExtensionPrincipalClass" key from the same place as that was preventing it from loading, after that it worked fine.

Olli
  • 512
  • 3
  • 6
  • 22
  • Ok, got it. The key for displaying the storyboard is a) remove the NSExtensionPrincipalClass and b) have ALL outlets you have defined connected. Then another hint: You cannot see "prints" from the extension, unless you are debugging the extension itself. Is valid for both, the SetupUI and the Extension itself. For me it works. A bit bumpy, but I get my samples and the storyboard now. – decades Apr 20 '19 at 17:09
1

Is your broadcast extension's storyboard configured in the extension's info plist?

Under the NSExtension dictionary you should add a key named "NSExtensionMainStoryboard" and the value should be the name of your storyboard ie - "MainInterface"

Are you able to set breakpoints that are called in the extensions also?

Javid
  • 51
  • 2
  • Hi Greg, did the info plist, UI still didn't show and I got `The user declined application recording` error(YouTube seemed to be getting this error too sometimes from online searches conducted), I put `print()` in the code instead of breakpoints and nothing got logged even when starting from the control center, I made a very simple Xcode project here with all I've done so far https://drive.google.com/file/d/1ObwzcVLanqvP0ligEsGrW8Mgn8WSIIxX/view?usp=sharing thanks – Olli Mar 04 '19 at 07:32
  • You were on the right track, besides your answer I left the NSExtensionPrincipalClass key in the Setup UI extension’s info.plist, and that was preventing the storyboard from loading, once removed it loaded – Olli Mar 05 '19 at 16:00