Screen Recording When My iOS App Is in Background with Replaykit

Screen recording when my iOS app is in background with ReplayKit

There is no "direct" way to store video in your app while it is in the background. ReplayKit version 2 allows you to get video sample buffer pieces in the app extensions that calls "Broadcast Upload Extension". When you say "Via Control center" it means that you start broadcast (not recording), and at the same time iOS finds your app-extension (not your application) and launch it, then begins send video sample buffers to the extension. On this step you need to decide what to do with these buffers.

I can propose two solutions for you:

  • you can try transfer buffers to the server (and download video when
    main application will be launched)
  • you can try save buffers to the file using App Groups (to share
    this data with the main application), you can find example
    here.

But you need to know that broadcast extension has been designed for buffer transferring, not to store or re rendering or compress or recode buffers. Extension has a lot of limitations based on CPU time and Memory usage (±50 MB), you can try to do anything there but if it is "heavy" operation iOS will close the extension.

Use ReplayKit to record any app on screen

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.

How to forward Screen Capture in iOS 11 Control Center to your App?

You need to add a Broadcast Upload Extension to your app.

(In Xcode, File > New Target, select "Broadcast Upload Extension")

Once the extension is installed (alongside your app), a force-touch on the screen recording icon in control center will give the option of using your broadcast extension, instead of the default ("Camera Roll").

There is very little documentation on iOS Screen Recording right now. But this WWDC video talks about it at a high level:

https://developer.apple.com/videos/play/wwdc2017/606/



Related Topics



Leave a reply



Submit