How do I know if screen recorder is Turned ON.

My applicaiton requires content not to be copied, and I have already blocked it from Ariplay/HDMi, Quicktime, but how do I stop it form screen recorder on iOS 11. I need a wasy to detect if screen recording is turned ON from control center.... Please help...

Answered by RyotzIwatz in 247434022

Use this UIScreen's new propertiy in iOS11 beta 4 `isCaptured`.

https://developer.apple.com/documentation/uikit/uiscreen/2921651-iscaptured

It is works well in beta4.

i have the same problem...still waiting for solution...

When screen recorder is turned on, it should be like this in control center: http://imgur.com/a/EVF0n (icon should be red while recording). Hope I could help you!

Apple’s engineers confirmed to me that there is a solution already:


1. Listen to the following notifications: UIScreenDidConnectNotification, UIScreenDidDisconnectNotification and UIScreenModeDidChangeNotification 2. When any of them fire, iterate through [UIScreen screens] and see if any of them have the mirroredScreen property set to YES as a way to detect if a user has activated iOS 11 screen recording


This was in response to my bug report,

32721460.

How to know UIScreen is screen recroding's screen or other mirrored screen (e,g. AirPlay)

I try to detect [UIScreen screens] on iOS11 iPhone, iPad.


In iPhone is well detect.


But i found iPad has different result :

non of them in [UIScreen screens] has mirroredScreen property (screen.mirroredScreen == nil)

you can determind by


CGSizeEqualToSize(mirrorScreen.currentMode.size, screen.currentMode.size)


if it's mirroring, they will have same size

In iOS 11 beta 3 there is no change in `UIScreen.screens`.

I have used the screen size methods to check if screen recording is in progress on iOS11 beta2, and it works.

However, it failed to detect screen recording actions on iOS11 beta3.


Don't know if Apple will fix this issue in iOS11 beta4 or offer another solution.

UIScreenDidConnectNotification, UIScreenDidDisconnectNotification and UIScreenModeDidChangeNotification are no longer working now with iOS11 Beta 3. Any other workaounds now..

UIScreenDidConnectNotification, UIScreenDidDisconnectNotification and UIScreenModeDidChangeNotification are no longer working now with iOS11 Beta 3. Any other workarounds now..

Did someone found any solution to it yet...

Accepted Answer

Use this UIScreen's new propertiy in iOS11 beta 4 `isCaptured`.

https://developer.apple.com/documentation/uikit/uiscreen/2921651-iscaptured

It is works well in beta4.

The property "isCaptured" is including mirrored and airplay.


Is there anyway to make sure the device is recording?

I checked this in iOS beta 4 and this is for screen recording and airplay mirror as well.

I am able to capture the event for recording start and end. I added the KVO in "captured" property.


@property(nonatomic,readonly,getter=isCaptured) BOOL captured NS_AVAILABLE_IOS(11_0); // True if this screen is being captured (e.g. recorded, AirPlayed, mirrored, etc.)



UIScreen *mainScreen = [UIScreen mainScreen];

[mainScreen addObserver:self forKeyPath:@"captured" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:NULL];



-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context{


AVAudioSession* audioSession = [AVAudioSession sharedInstance];

AVAudioSessionRouteDescription* currentRoute = audioSession.currentRoute;

for (AVAudioSessionPortDescription* outputPort in currentRoute.outputs){

if ([outputPort.portType isEqualToString:AVAudioSessionPortAirPlay]){

NSLog(@"%@",outputPort.portName);

NSLog(@"%@",outputPort.portType);

return;

}

}


if ([keyPath isEqualToString:@"captured"]) {

id oldC = [change objectForKey:NSKeyValueChangeOldKey];

id newC = [change objectForKey:NSKeyValueChangeNewKey];

NSLog(@"%d %d", [oldC boolValue], [newC boolValue]);

if (newC) {

/

}

}

}

Yeah, that property is really useful. But I still want to build my codebase with Xocde8 (i.e. old binaries), because shifting to new Xcode would bring me more changes to take care. Any solutions?

I have found 1 soultion:

https://medium.com/swiftist/how-to-use-ios-11-beta-installed-device-with-xcode-8-c255b916aca5


But not sure, about its side effects. Any pointer/drawbacks of this approach?

try it if you need to build with xcode8

BOOL isCaptured = NO;

@try

{

isCaptured = [[[UIScreen mainScreen] valueForKey:@"isCaptured"] boolValue];

}

@catch (NSException * e) {

}

Did you get this to compile? Properties unrecognized by the Xcode 8.3.3 compiler will throw fatal errors.


Wrapping the iOS 11 specific code like this will allow compiling on prior versions of Xcode that do not know about iOS 11:


#ifdef __IPHONE_11_0

...

//Wrapping iOS 11 methods and properties in this if statement will allow Xcode to compile to earlier iOS versions:

if (@available(iOS 11_0, *)) {

...

}

...

#endif


This technique successfully handles detection for iOS 11 when compiled in Xcode 9 and still allows support of earlier OS's.

Hi Guys,

We work on HLS+Fairplay, and found isCaptured can not be observerd in playback Fairplay content.

Nevertheless, if play clear content, it can work.


Could anyone have idea to workaround this issue?


We know even it can be recorded but just black screen, but we focus on better ux, want to show dialog

to remind user can not record video content


Code snippet :

[[UIScreen mainScreen] addObserver:self forKeyPath:@"captured" options:NSKeyValueObservingOptionNew context:nil];

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
     // observe well when play clear content, but failed in HLS+FairPlay (Please note video should be playback, it can work before ckc verified)
    if ([keyPath isEqualToString:@"captured"]) {
        BOOL isCaptured = [change[NSKeyValueChangeNewKey] boolValue];
       //blablabla
    }

}


Another notification still can not get event in fairplay mode


[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(screenDidChangeNotification:) name:UIScreenCapturedDidChangeNotification object:nil];

isCaptured is a UIScreen property, specific to each screen - main or attached. Are you saying that Fairplay is overriding the access to this property on all of the screens?


I haven't tried recording an external screen, but have had success detecting all changes to this property with the main screen [UIScreen mainScreen]. And I check every screen in the screens array prior to playback operations to see if its isCaptured is set.

Hi robvandy55,


Sorry for my not clear expression, there is key point I should describe.


1. Play FairPlay content (Make sure it can play / pause )

2. Go back background, enable "Screen Record"

3. Immediately back to FairPlay player page (You must be fast than record countdown number, eg: earlier than 3 seconds)

4. Polling to get isCapured value, it always return false


5. Go back background againg, and do nothing.

6. back to FairPlay Player page, isCaptured will return true


Thank you~

Not sure why are you trying this..

  1. if ([keyPath isEqualToString:@"captured"]) {
  2. BOOL isCaptured = [change[NSKeyValueChangeNewKey] boolValue];
  3. //blablabla
  4. }



In my case, I am checking the property directly as soon as I get notification, and getting the correct value, by using:

[[[UIScreen mainScreen] valueForKey:@"captured"] boolValue]


And also add notificaiton for NSKeyValueObservingOptionOld value too, as:

[[UIScreen mainScreen] addObserver:self forKeyPath:@"captured" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil];

isCaptured is not working properly when user tries to stop the screen share from top left red icon from outside the app, it gives before taking the input screen share popup.

anyone has any idea ?

How do I know if screen recorder is Turned ON.
 
 
Q