From ba6017689f52680fd74c09ff516142a1c1a6bf38 Mon Sep 17 00:00:00 2001 From: Felizolinha Date: Mon, 26 Feb 2018 11:44:37 -0300 Subject: [PATCH 1/2] Fixed black screen while broadcasting The broadcast controller that came from the broadcastActivityViewController wasn't being stored anywhere, which in turn made it be deinstantiated, thus not able to broadcast the screen. --- GoLive/ViewController.swift | 41 +++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/GoLive/ViewController.swift b/GoLive/ViewController.swift index cce81be..69d0cd7 100644 --- a/GoLive/ViewController.swift +++ b/GoLive/ViewController.swift @@ -19,7 +19,7 @@ class ViewController: UIViewController, RPBroadcastActivityViewControllerDelegat @IBOutlet var micSwitch: UISwitch! @IBOutlet var micLabel: UILabel! - let controller = RPBroadcastController() + var controller: RPBroadcastController? let recorder = RPScreenRecorder.shared() override func viewDidLoad() { @@ -29,10 +29,9 @@ class ViewController: UIViewController, RPBroadcastActivityViewControllerDelegat @IBAction func didPressBroadcastButton() { // Called when broadcast button is tapped. Runs functions to start or stop broadcast. - if controller.isBroadcasting { + if let isBroadcasting = controller?.isBroadcasting, isBroadcasting { stopBroadcast() - } - else { + } else { startBroadcast() } } @@ -64,6 +63,9 @@ class ViewController: UIViewController, RPBroadcastActivityViewControllerDelegat print("Broadcast Activity Controller is not available.") return } + if let bcController = broadcastController { + self.controller = bcController + } //2 broadcastActivityViewController.dismiss(animated: true) { @@ -82,7 +84,7 @@ class ViewController: UIViewController, RPBroadcastActivityViewControllerDelegat func stopBroadcast() { - controller.finishBroadcast { error in + controller?.finishBroadcast { error in if error == nil { print("Broadcast ended") self.broadcastEnded() @@ -92,21 +94,25 @@ class ViewController: UIViewController, RPBroadcastActivityViewControllerDelegat func broadcastStarted() { - // Called to update the UI when a broadcast starts. - broadcastButton.setTitle("Stop Broadcast", for: .normal) - statusLabel.text = "You are live!" // Any app that does not notify the user that they are live will be rejected in app review. - statusLabel.textColor = UIColor.red - micSwitch.isHidden = false - micLabel.isHidden = false + DispatchQueue.main.sync { + // Called to update the UI when a broadcast starts. + broadcastButton.setTitle("Stop Broadcast", for: .normal) + statusLabel.text = "You are live!" // Any app that does not notify the user that they are live will be rejected in app review. + statusLabel.textColor = UIColor.red + micSwitch.isHidden = false + micLabel.isHidden = false + } } func broadcastEnded() { - // Called to update the UI when a broadcast ends. - broadcastButton.setTitle("Start Broadcast", for: .normal) - statusLabel.text = "You are not live" - statusLabel.textColor = UIColor.black - micSwitch.isHidden = true - micLabel.isHidden = true + DispatchQueue.main.sync { + // Called to update the UI when a broadcast ends. + broadcastButton.setTitle("Start Broadcast", for: .normal) + statusLabel.text = "You are not live" + statusLabel.textColor = UIColor.black + micSwitch.isHidden = true + micLabel.isHidden = true + } } @@ -153,4 +159,3 @@ class ViewController: UIViewController, RPBroadcastActivityViewControllerDelegat } - From 57707eab00dff38effaab1d6baf4eba243d901ce Mon Sep 17 00:00:00 2001 From: Felizolinha Date: Mon, 26 Feb 2018 11:55:13 -0300 Subject: [PATCH 2/2] Added missing outlet to microphone label Fixes a crash when trying to access the microphone label from code. --- GoLive/Base.lproj/Main.storyboard | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/GoLive/Base.lproj/Main.storyboard b/GoLive/Base.lproj/Main.storyboard index 4693a5b..3c72553 100644 --- a/GoLive/Base.lproj/Main.storyboard +++ b/GoLive/Base.lproj/Main.storyboard @@ -1,11 +1,11 @@ - + - + @@ -104,6 +104,7 @@ +