Plugin.Maui.ScreenSecurity 、コンテンツの露出を防ぐためのシームレスなソリューションを提供します。
| プラットフォーム | バージョン |
|---|---|
| .net maui android | API 21+ |
| .net maui ios | iOS 14+ |
| Windows | 10.0.17763+ |
IsProtectionEnabledプロパティを追加して、画面保護が既に有効または無効になっているかどうかを確認します。ScreenCapturedイベントハンドラーが追加されました。Blazorサンプルを追加しました。ここをクリックして、完全なChangelogをご覧ください!
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ファイル(Platforms/Android)に次の許可を追加します。
< uses-permission android : name = " android.permission.DETECT_SCREEN_CAPTURE " />最後に、プラグインのデフォルトインスタンスをシングルトンとして追加して、コードに遅れて挿入します。
builder . Services . AddSingleton < IScreenSecurity > ( ScreenSecurity . Default ) ; ユーザーがスクリーンショットやアプリの録音を撮影しないようにすることは、困難なタスクであり、完全な予防を達成することは実行不可能である可能性があることを認識することが重要です。別の物理デバイスやOSの潜在的な違反を介して画面がキャプチャされる可能性を完全に排除できる方法はないことは注目に値します。
また、これらの方法のいずれかを実装し、アプリのセキュリティ上の懸念とバランスをとる際には、ユーザーエクスペリエンスへの影響を考慮することも重要です。
まだバージョン1.0.0を使用している場合は、以前のバージョンのレガシードキュメントを参照してください。
新しいUnified APIには、iOSプラットフォームにのみ適用可能なオプションのパラメーターを使用して、 ActivateScreenSecurityProtection()とDeactivateScreenSecurityProtection()の2つの方法が含まれています。また、保護がアクティブであるかどうかをチェックするIsProtectionEnabledと、スクリーンショットがいつ使用されるか、画面が記録されるかを通知するScreenCapturedイベントハンドラーの2つのプロパティも提供します。
void ActivateScreenSecurityProtection ( ) ;この保護をアクティブにすると、アプリのコンテンツがレシート画面またはアプリスイッチャーに送信されると保護されます。これにより、機密情報が公開されないようにすることができます。
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 ; }このブールは、画面保護が有効になっているかどうかを確認します。
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に遭遇したり、PRを提出したりした場合は、お気軽に開かれてください。あなたの貢献は大歓迎です。
Plugin.maui.screensecurityは、MITライセンスに基づいてライセンスされています。