Search code examples
swiftreplaykit

Check if Screen is recording swift


I am trying to check if the screen is recording before allowing a following action, I initially tried to use ReplayKit to automatically record, but this isn't a viable solution because it doesn't allow for recording outside the app, so basically what I want to do is check if the user has began screen recording using the IOS Control Centre recorder, before allowing them to execute another piece of code.

Something like:

func handleScreen() {
    var isRecording: Bool = false

    if ScreenIsRecording { //(this is what i don't know how to check) 
       isRecording = true 
    }

    if isRecording == true {
     //   execute this code.
    }
            
}

I am open to other solutions of being able to execute screen recording, but it has to be able to record all screens not just the in-app screen.

Thanks


Solution

  • UIScreen includes the UIScreen.isCaptured property which you should be able to reference to determine if the screen is likely being recorded. However this will also return true if the device is being AirPlayed or otherwise broadcast:

    A value of YES indicates the system is actively recording, mirroring, or using AirPlay to stream the contents of the screen.

    if UIScreen.mainScreen().isCaptured {
        isRecording = true
    }