iOS Question Detect screen recording

nwhitfield

Active Member
Licensed User
Longtime User
I warn users when they take screenshots in my app that they may be breaching the privacy of other users if they share personal information, using the code from this question

I would like to also display something if a user tries a screen recording as well. I have found the Technical note from Apple about how to respond, which is here, but I'm still a little unclear on how exactly one creates a listener or checks the value of a property using inline Objective C.

Any pointers would be much appreciated.

Nigel
 

JanPRO

Well-Known Member
Licensed User
Longtime User
Hi,

you can use the following code snippet:
B4X:
Private Sub Application_Start (Nav As NavigationController)
   NavControl = Nav
   Page1.Initialize("Page1")
   Page1.Title = "Page 1"
   Page1.RootPanel.Color = Colors.White
   NavControl.ShowPage(Page1)
   SetEvent
End Sub

Sub ScreenIsCaptured As Boolean
    Dim no As NativeObject
    Return no.Initialize("UIScreen").RunMethod("mainScreen", Null).GetField("isCaptured").AsBoolean
End Sub

Sub SetEvent
    Dim no As NativeObject = Me
    no.RunMethod("AddEvent", Null)
    #if OBJC
        - (void)AddEvent {
          [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_capture_change) name:UIScreenCapturedDidChangeNotification object:nil];
        }
    #end if
End Sub

Private Sub Capture_Change
    Log(ScreenIsCaptured)
End Sub

Set the #MinVersion of your App (in the Project Attributes region) to 11+

Jan
 
Upvote 0

nwhitfield

Active Member
Licensed User
Longtime User
Great, thanks.

Is there a way to make the conditional on the iOS version? I would like to still be able to support people using older devices, like an iPhone 5, which won't ever get beyond iOS 10.
 
Upvote 0

JanPRO

Well-Known Member
Licensed User
Longtime User
Hi,

I am not 100% sure, but in this case I think it's enough to just the check the OS:
B4X:
    Dim Version As Float = App.OSVersion
    If Version >= 11 Then SetEvent

I guess, when the framwork would be completly new, this wouldn't work.

Jan
 
Upvote 0
Top