1. 안드로이드
"보안정책에 따라 화면을 캡처할 수 없어요." 토스트 메시지가 표출되면서 캡쳐 불가능하도록 구현
main.dart
@override
initState() {
super.initState();
//스크린샷 방지
if (Platform.isAndroid) {
FlutterWindowManager.addFlags(FlutterWindowManager.FLAG_SECURE);
}
...(코드생략)
}
2. iOS
iOS는 캡쳐 자체를 막을 수 는 없기 때문에 스크린샷이 감지되었다는 토스트 메시지가 출력되는게 기본적이지만,
그것마저도 되지 않게 검은색 화면으로 캡쳐되도록 구현
AppDelegate.swift
import UIKit
import Flutter
import flutter_downloader
import WebKit
import Firebase
import FirebaseCore
@main
@objc class AppDelegate: FlutterAppDelegate {
private var textField = UITextField()
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
FirebaseApp.configure()
UNUserNotificationCenter.current().delegate = self
//스크린샷 방지
self.window.makeSecure()
GeneratedPluginRegistrant.register(with: self)
FlutterDownloaderPlugin.setPluginRegistrantCallback(registerPlugins)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
...(코드 생략)
//스크린샷 방지
extension UIWindow {
func makeSecure() {
let field = UITextField()
let view = UIView(frame: CGRect(x: 0, y: 0, width: field.frame.self.width, height: field.frame.self.height))
field.isSecureTextEntry = true
self.addSubview(field)
self.layer.superlayer?.addSublayer(field.layer)
field.layer.sublayers?.last!.addSublayer(self.layer)
field.leftView = view
field.leftViewMode = .always
}
}
//스크린샷 방지 주석처리 된 부분만 코드 추가해주면 된다.
'프로그래밍 언어 > Flutter' 카테고리의 다른 글
[Flutter] 웹뷰 안드로이드 이미지 파일 첨부 오류 (0) | 2025.03.01 |
---|---|
[Flutter] iOS 파일 다운로드(파일 앱 저장, 공유하기 팝업창 생성) (0) | 2025.03.01 |