1

How do I present the RPBroadcastActivityViewController on iPads.

I am using the standard code to start a recording

   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(...
        }
    }

Works on iPhones but on iPads nothing is presented and the app kind of freezes. I have been checking out games on the app store that use this feature and I noticed the same problem.

E.g on the game Tower Dash nothing is presented when pressing the live stream button on iPads, it only works on iPhones.

I have been trying to play around with popover presentations but nothing seems to work.

Am I missing something?

UPDATE: This seems to be a bug. Even in apples own Swift Playground app this happens.

UPDATE2: Apple has actually responded to my bug report and told me that I need to present the View Controller on iPads as a popover like so

  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
  }

However it still doesnt work for me. As I mentioned this happens on apples own Swift Playground app so it must be a bug.

Fixed:

I forgot to add this line in the code mentioned above

 broadcastAVC.modalPresentationStyle = .popover
crashoverride777
  • 10,581
  • 2
  • 32
  • 56
  • did you write a bug report? – Dima Deplov Sep 28 '16 at 01:21
  • Yes, I did. I think this must be a bug because it happens with their own swift playground app as well. Haven't heard back from them yet (28411422) – crashoverride777 Sep 28 '16 at 09:37
  • Hope they will fix this soon :) – Dima Deplov Sep 29 '16 at 01:21
  • 1
    They actually wrote back to me on the bug report. They say I need to present the view controller on iPads as a pop-over, similar to what you have to do when you want to present a UIActivityController on iPads. Still doesnt work for me tho. – crashoverride777 Oct 02 '16 at 12:37
  • 2
    I forgot to add this line of code ...modalPresentationStyle = .popover. – crashoverride777 Nov 19 '16 at 14:53
  • 1
    Hello! Does it actually work on iOS 10.1? I still have some problems, it simply doesn't do anything and I see this warning in debugger console (using Xcode 10) "viewServiceDidTerminateWithError" Can you help me, please? Thanks in advance! – Alex Dec 09 '16 at 09:23
  • Hey, yeah works fine for me. Not sure what that message means. Maybe ask a question and I will have a look – crashoverride777 Dec 09 '16 at 11:01
  • Could you please share some sample project or code snippet? Because I still get the same error, my UI just freezes :( I followed your example 100% and still no success – Alex Dec 14 '16 at 10:15
  • Why don't you post a question and I have a look – crashoverride777 Dec 15 '16 at 09:42
  • Did you ever get this working? – SuddenMoustache Apr 08 '20 at 14:41
  • Hey, did you try some of the provided answer?. I did get it working but I don't have the code anymore because I removed ReplayKit from my games quite a while ago. Its basically a native iOS feature now in control centre so felt like it wasn't needed anymore. If you present as popover and attach it correctly it should work. – crashoverride777 Apr 09 '20 at 15:47

2 Answers2

1

You are correct that Apple's demo app does not include this little detail, but it isn't a bug. This is what I use to get it to work on an iPad. iPads require a popover to present the view and a popover needs an anchor. I chose to anchor it to the 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)

            }
        }
Chris3643
  • 48
  • 7
  • Hey, Thanks for your answer. Any idea why this is not working for me?. I am doing this already (see update 2 of my question) and it is still not working. Its the same code I use for UIActivityControllers as well and it works there. – crashoverride777 Nov 07 '16 at 11:45
  • 1
    Fixed. I forgot to add this line of code ...modalPresentationStyle = .popover. Thank you for your help. – crashoverride777 Nov 19 '16 at 14:48
0

iOS 10.1 beta 2 still have the same problem.

For now, I found the only way to present a RPBroadcastActivityViewController on iPad is to present it on a trait collection's horizontal compact environment.

So you may need to tell your user switch to Split View mode before select a broadcast-supported app, then switch back to full screen. After back to full screen, you can use RPBroadcastController.startBroadcast(handler:) to start broadcast.

Jonny
  • 1,969
  • 18
  • 25