2

I am trying to create an iPhone app that records not only the app's screen but if put into the background it records everything on the screen, including other apps. This is how recording from "Control Center" works. The difference is I want to get access to the video immediately without user intervention, with the user's consent of course.

I've implemented code using ReplayKit2 on iOS 12 that uses an embedded Broadcast Upload Extension. I have not found any examples online that work like this.

I posted the code on Bitbucket: https://bitbucket.org/breelig/replaykitbroadcasttofile/src/master/

The closet similar question I found on SO is: ReplayKit stops screen recording in background mode of the application or outside the app?

Update

Based on the good responses by @KaneCheshire and @AndreyA. below and other random sources I was able to develop a solution that works. Please see the code in my BitBucket link above.

3 Answers3

3

From the docs:

Apps on a user’s device can share the recording function, with each app having its own instance of RPScreenRecorder. Your app can record the audio and video inside of the app, along with user commentary through the microphone

The only other way to record the screen is through a Broadcast Upload Extension, which requires the user to initiate it through Control Centre.

Kane Cheshire
  • 1,654
  • 17
  • 20
  • Thank you @KaneCheshire. I am using a Broadcast Upload Extension embedded in my app. The host app loads the extension, the user accepts the request to record the screen, and the extension takes over processing the video samples. –  Feb 05 '19 at 12:26
  • 2
    I figured it out. I have to start the screen recording from the "Screen Recording" button in Control Center. To choose my Broadcast Upload Extension, I must press and hold the "Screen Recording" button until a list of Broadcast Extensions appear. –  Feb 06 '19 at 12:29
  • 1
    Yeah sorry I could have been more clear. Although, I do feel like it's Apple's job to make their UI a bit more obvious! – Kane Cheshire Feb 07 '19 at 09:34
2

I've faced almost the same problem that you did and it's absolutely lacking any kind of guides or documentation. The way I resolved this problem to myself is setting nil to my preferred extensions, so it makes RPSystemBroadcastPickerView to show all of them including system screen video capture:

override func viewDidLoad() {
    super.viewDidLoad()

    let broadcastPicker = RPSystemBroadcastPickerView(frame: CGRect(x: 100, y: 100, width: 80, height: 80))
    broadcastPicker.preferredExtension = nil

    view.addSubview(broadcastPicker)
}

Also I've found one thing that I've figured out to be useful - this Twilio lib and its example - https://github.com/twilio/video-quickstart-swift/tree/master/ReplayKitExample - These guys have made a decent work in area of video/audio capturing and we can try to use their experience.

Andrey A.
  • 19
  • 2
  • Very interesting. I tried this but set preferredExtension to my extension's bundle ID. `self.pickerView!.preferredExtension = "com.breelig.ReplayKitBroadcastToFile.BroadcastLocal"` It does send the video to my broadcast extension but there is a bug in my code that saves the video resulting in it being corrupt. I will post the result if I can figure it out. –  Feb 19 '19 at 10:16
-1

You can find your exactly preferedExtension here:

image

When you add pickerView.preferredExtension exactly the Bundle Identifier, your app will be showed on the Recording App List. Hope this helps!

ANDYNVT
  • 531
  • 4
  • 19