Plugin.Maui.ScreenSecurity 컨텐츠 노출 방지 및 .NET MAUI 애플리케이션 내 스크린 샷 및 녹음 차단을위한 완벽한 솔루션을 제공합니다.
| 플랫폼 | 버전 |
|---|---|
| .NET Maui Android | API 21+ |
| .NET Maui iOS | iOS 14+ |
| 창 | 10.0.17763+ |
IsProtectionEnabled 속성이 추가되었습니다.ScreenCaptured 이벤트 핸들러가 추가되어 스크린 샷을 찍거나 화면이 기록 될 때 알림을 트리거합니다.Blazor 샘플을 추가했습니다.전체 변경 로그를 보려면 여기를 클릭하십시오!
Plugin.Maui.ScreenSecurity Nuget을 통해 제공되며 최신 패키지를 잡고 솔루션에 설치하십시오.
Install-Package Plugin.Maui.ScreenSecurity
MauiProgram 클래스에서 플러그인을 초기화하십시오.
using Plugin . Maui . ScreenSecurity ;
public static MauiApp CreateMauiApp ( )
{
var builder = MauiApp . CreateBuilder ( ) ;
builder
. UseMauiApp < App > ( )
. ConfigureFonts ( fonts =>
{
fonts . AddFont ( "OpenSans-Regular.ttf" , "OpenSansRegular" ) ;
fonts . AddFont ( "OpenSans-Semibold.ttf" , "OpenSansSemibold" ) ;
} )
. UseScreenSecurity ( ) ;
return builder . Build ( ) ;
} Android.manifest 파일 (플랫폼/Android)에서 다음과 같은 권한을 추가하십시오.
< uses-permission android : name = " android.permission.DETECT_SCREEN_CAPTURE " />마지막으로 플러그인의 기본 인스턴스를 싱글 톤으로 추가하여 코드에 늦게 주입하십시오.
builder . Services . AddSingleton < IScreenSecurity > ( ScreenSecurity . Default ) ; 사용자가 스크린 샷을 찍거나 앱의 녹음을하는 것을 방지하는 것은 어려운 작업이 될 수 있으며 완전한 예방을 달성하는 것은 불가능할 수 있음을 인정하는 것이 중요합니다. 어떤 방법도 다른 물리적 장치를 통해 화면을 캡처하거나 OS의 잠재적 인 위반 가능성을 완전히 제거 할 수 없다는 점은 주목할 가치가 있습니다.
이러한 방법을 구현하고 앱의 보안 문제와 균형을 잡을 때 사용자 경험에 미치는 영향을 고려하는 것이 중요합니다.
여전히 버전 1.0.0을 사용하는 경우 이전 버전의 레거시 문서를 참조하십시오.
새로운 Unified API에는 두 가지 방법이 포함되어 있습니다 : ActivateScreenSecurityProtection() 및 DeactivateScreenSecurityProtection() 은 iOS 플랫폼에만 적용 가능한 선택적 매개 변수를 제공합니다. 또한 보호가 활성화되어 있는지 확인하는 IsProtectionEnabled 및 ScreenCaptured 이벤트 핸들러가 스크린 샷을 찍거나 화면이 기록 될 때 알립니다.
void ActivateScreenSecurityProtection ( ) ;이 보호를 활성화하면 앱 컨텐츠가 Recents 화면 또는 앱 스위처로 전송되면 보호됩니다. 이것은 민감한 정보가 노출되지 않도록하는 데 도움이됩니다.
void ActivateScreenSecurityProtection ( bool blurScreenProtection , bool preventScreenshot , bool preventScreenRecording ) ;이 방법은 이전 방법과 유사하지만 iOS의 기본값을 변경하는 매개 변수가 있습니다.
blurScreenProtection : 화면 흐림을 활성화/비활성화하여 백그라운드의 콘텐츠 가시성을 방지합니다. 기본적으로 사실입니다 .preventScreenshot : 사용자가 앱의 스크린 샷을 찍을 수 있는지 여부를 결정합니다. 기본적으로 사실입니다 .preventScreenRecording : 앱을 사용하는 동안 사용자가 화면을 녹화 할 수 있는지 제어합니다. 기본적으로 사실입니다 . void ActivateScreenSecurityProtection ( ScreenProtectionOptions screenProtectionOptions ) ; 이 방법은 원래 방법과 유사하지만 ScreenProtectionOptions 매개 변수를 취합니다. 이를 통해 iOS 장치의 스크린 샷 및 화면 녹화 보호와 함께 색상 또는 이미지를 지정하여 화면 보호를 더 사용자 정의 할 수 있습니다.
참고 : 색상 과 이미지를 모두 설정하면 먼저 선언 한 것만 적용됩니다.
ScreenProtectionOptions 속성 :
Color : 16 진수 형태의 색상을 나타내며 색상 레이어를 사용자 정의하기위한 인수로 전달 될 수 있습니다. #RGB , #RGBA , #RRGGBB 또는 #RRGGBBAA 와 같은 형식을 지원합니다. 기본적으로 비어 있습니다 .Image : 확장자와 함께 이미지 파일의 이름입니다. 이 속성을 활용하려면 다음을 수행하십시오.ResourcesImages 폴더 내부에서 사용하려는 이미지를 저장하십시오.MauiImage 로 설정 한 후 이미지를 인식하지 못하면 빌드 동작을 Embedded resource 로 변경하여 올바른 기능을 보장하십시오.PreventScreenshot : 사용자가 앱의 스크린 샷을 찍을 수 있는지 여부를 결정합니다. 기본적으로 사실입니다 .PreventScreenRecording : 앱을 사용하는 동안 사용자가 화면을 녹화 할 수 있는지 제어합니다. 기본적으로 사실입니다 . void DeactivateScreenSecurityProtection ( ) ;이 방법은 모든 화면 보안 보호를 비활성화합니다.
bool IsProtectionEnabled { get ; }이 bool은 화면 보호가 활성화되어 있는지 확인합니다.
event EventHandler < EventArgs > ? ScreenCaptured ;이벤트 핸들러는 스크린 샷 또는 Android 및 iOS의 녹음을 통해 화면이 캡처되면 Windows의 스크린 샷에 대해서만 트리거됩니다.
public partial class MainPage : ContentPage
{
private readonly IScreenSecurity _screenSecurity ;
public MainPage ( IScreenSecurity screenSecurity )
{
InitializeComponent ( ) ;
_screenSecurity = screenSecurity ;
}
protected override void OnAppearing ( )
{
base . OnAppearing ( ) ;
// Check if screen security protection is not enabled
if ( ! _screenSecurity . IsProtectionEnabled )
{
// Activate the screen security protection with default settings
_screenSecurity . ActivateScreenSecurityProtection ( ) ;
}
// Attach to the ScreenCaptured event handler
_screenSecurity . ScreenCaptured += OnScreenCaptured ;
/*
// For changing iOS options, follow one of the next examples:
// Example 1: Customize with a specific color
var screenProtectionOptions = new ScreenProtectionOptions
{
HexColor = "#6C4675",
PreventScreenshot = true,
PreventScreenRecording = false
};
// Example 2: Customize with an image
var screenProtectionOptions = new ScreenProtectionOptions
{
Image = "protection_bg.png"
PreventScreenshot = false,
PreventScreenRecording = true
};
_screenSecurity.ActivateScreenSecurityProtection(screenProtectionOptions);
*/
}
protected override void OnDisappearing ( )
{
_screenSecurity . DeactivateScreenSecurityProtection ( ) ;
// Detach from the ScreenCaptured event handler
_screenSecurity . ScreenCaptured -= OnScreenCaptured ;
base . OnDisappearing ( ) ;
}
private async void OnScreenCaptured ( object sender , EventArgs e )
{
string title = "ScreenSecuritySample" ;
string message = "Screen was captured by screenshot or recording." ;
await Shell . Current . DisplayAlert ( title , message , "Ok" ) ;
}
} 이 플러그인의 포괄적이고 자세한 구현은 ScreensecuritySample을 참조하여 사용에 대한 완전한 이해를 제공합니다.
버그가 발생하거나 PR을 제출하여 개선 또는 수정 사항을 제공하는 경우 문제를 열어주십시오. 귀하의 기여는 대단히 감사합니다.
플러그인 .maui.screensecurity는 MIT 라이센스에 따라 라이센스가 부여됩니다.