Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bloquer les captures ou enregistrements d'écran #1048

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Riot/Modules/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
let window = UIWindow(frame: UIScreen.main.bounds)
self.window = window

// Tchap: secure window to prevent screenshot and screen recording (only in PRODUCTION environment)
#if TCHAP_PRODUCTION
window.makeSecure()
#endif

// Create AppCoordinator
self.rootRouter = RootRouter(window: window)

Expand Down
54 changes: 54 additions & 0 deletions Tchap/Extensions/UIWindow+Tchap.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// Copyright 2024 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import UIKit

extension UIWindow {

// Screen recording can be prevented on iOS by listening to `UIScreen.capturedDidChangeNotification` and masking the screen content.
//
// But screenshot cannot be prevented.
// We can be informed the user made a screenshot by listening to `UIApplication.userDidTakeScreenshotNotification`,
// but we are informed after the screenshot took place and cannot mask any screen content because it's too late.
//
// But iOS auto mask content of Secured UITextField when capturing or recording screen.
//
// The hack is too embed any view (such as root window) in a Secured UITextField and iOS will mask it on screen capture or recording.
//
// Any screen capture or recording will end in a blank picture or movie in the Photos gallery.

// from: https://stackoverflow.com/a/77922186/399439

func makeSecure() {
let field = UITextField()

let view = UIView(frame: CGRect(x: 0, y: 0, width: field.frame.self.width, height: field.frame.self.height))

let image = UIImageView(image: UIImage())
image.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)

field.isSecureTextEntry = true

self.addSubview(field)
view.addSubview(image)

self.layer.superlayer?.addSublayer(field.layer)
field.layer.sublayers?.last!.addSublayer(self.layer)

field.leftView = view
field.leftViewMode = .always
}
}
1 change: 1 addition & 0 deletions changelog.d/797.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bloquer les captures ou enregistrements d'écran
Loading