Plugin.Maui.ScreenSecurity 1.0.7-beta

This is a prerelease version of Plugin.Maui.ScreenSecurity.
There is a newer version of this package available.
See the version list below for details.
dotnet add package Plugin.Maui.ScreenSecurity --version 1.0.7-beta                
NuGet\Install-Package Plugin.Maui.ScreenSecurity -Version 1.0.7-beta                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Plugin.Maui.ScreenSecurity" Version="1.0.7-beta" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Plugin.Maui.ScreenSecurity --version 1.0.7-beta                
#r "nuget: Plugin.Maui.ScreenSecurity, 1.0.7-beta"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Plugin.Maui.ScreenSecurity as a Cake Addin
#addin nuget:?package=Plugin.Maui.ScreenSecurity&version=1.0.7-beta&prerelease

// Install Plugin.Maui.ScreenSecurity as a Cake Tool
#tool nuget:?package=Plugin.Maui.ScreenSecurity&version=1.0.7-beta&prerelease                

Plugin.Maui.ScreenSecurity

NuGet

Plugin.Maui.ScreenSecurity provides a seamless solution for preventing content exposure, as well as blocking screenshots and recordings within your .NET MAUI application

Platforms supported

Platform Version
.Net MAUI Android API 21+
.Net MAUI iOS iOS 14+

Installation

Plugin.Maui.ScreenSecurity is available via NuGet, grab the latest package and install it on your solution:

Install-Package Plugin.Maui.ScreenSecurity

In your MauiProgram class add the following using statement:

using Plugin.Maui.ScreenSecurity;

Finally, add the default instance of the plugin as a singleton to inject it in your code late:

builder.Services.AddSingleton<IScreenSecurity>(ScreenSecurity.Default);

⚠️ WARNING ⚠️

It's important to acknowledge that preventing users from taking screenshots or recordings of your app can be a challenging task and achieving complete prevention may not be feasible. It's worth noting that no method can entirely eliminate the possibility of your screen being captured through another physical device or a potential breach in the OS.

👉 It's also important to consider the impact on user experience when implementing any of these methods and striking a balance with the security concerns of your app.


API Usage

Call the injected interface in any page or viewmodel to gain access to the APIs.

Given that each platform handles this functionality internally in a distinct manner, we will utilize processor directives to access the specific implementation for each platform.

Android

/// <remarks>Supported for Android only.</remarks>
void EnableScreenSecurityProtection();

This method provides enhanced protection for screen content by preventing exposure when the app is sent to the Background or displayed on the Recents screen. It also effectively prevents unauthorized screenshots or recordings from being captured.

If the method fails, a message will be displayed on the Console and no Exepction will be thrown.

/// <remarks>Supported for Android only.</remarks>
void DisableScreenSecurityProtection();

This method desable protection and re-enables screen content exposure.

If the method fails, a message will be displayed on the Console and no Exepction will be thrown.

Example

This method can also be attached to a single page by using it on the OnAppearing and OnDisappearing methods.

protected override void OnAppearing()
{
    base.OnAppearing();

#if ANDROID
    _screenSecurity.EnableScreenSecurityProtection();
#endif
}

protected override void OnDisappearing()
{
#if ANDROID
    _screenSecurity.DisableScreenSecurityProtection();
#endif

    base.OnDisappearing();
}

iOS

Preventing screenshots on iOS can be a complex task that may not always be effective unless we utilize paid software like ScreenShieldKit. However, there are various methods available to protect the content of our screen when sending the app to the Background or switching between apps. Additionally, some methods help to prevent the app screen from being recorded by the system or any external application.

Blur Screen Protection
/// <param name="style">Choose between a Light or Dark theme for the Blur layer. Light by default.</param>
/// <remarks>Supported for iOS only.</remarks>
void EnableBlurScreenProtection(ThemeStyle style);

This method ensures that your app screen content remains protected by applying a blur layer when the app is sent to the Background or displayed on the App Switcher.

To choose between a light or dark Blur, you can pass the style property as an argument to this method. By default, it uses a Light Blur.

If the method fails, a message will be displayed on the Console and no Exepction will be thrown.

/// <remarks>Supported for iOS only.</remarks>
void DisableBlurScreenProtection();

This method removes the Blur layer, thereby re-enabling the exposure of screen content.

If the method fails, a message will be displayed on the Console and no Exepction will be thrown.

Example

This method can also be attached to a single page by using it on the OnAppearing and OnDisappearing methods.

private void ActivateBlurProtection_Clicked(object sender, EventArgs e)
{
#if IOS
    var theme = Application.Current.RequestedTheme;

    var style = theme == AppTheme.Dark ? ThemeStyle.Dark : ThemeStyle.Light;

    _screenSecurity.EnableBlurScreenProtection(style);
#endif
}

private void DeactivateBlurProtection_Clicked(object sender, EventArgs e)
{
#if IOS
    _screenSecurity.DisableBlurScreenProtection();
#endif
}
Color Screen Protection
/// <param name="hexColor">Hexadecimal color as string in the form of #RGB, #RGBA, #RRGGBB or #RRGGBBAA.</param>
/// <remarks>Supported for iOS only.</remarks>
void EnableColorScreenProtection(string hexColor);

This method will prevent screen content from being exposed by using a color layer when the app is sent to Background or the App Switcher.

The hexColor property represents a color in the form of a hexadecimal string and can be passed as an argument to customize the color layer. It supports formats such as #RGB, #RGBA, #RRGGBB, or #RRGGBBAA. By default, the color is set to white (#FFFFFF).

If the method fails, a message will be displayed on the Console and no Exepction will be thrown.

/// <remarks>Supported for iOS only.</remarks>
void DisableColorScreenProtection();

This method removes the color layer, thereby re-enabling the exposure of screen content.

If the method fails, a message will be displayed on the Console and no Exepction will be thrown.

Example

This method can also be attached to a single page by using it on the OnAppearing and OnDisappearing methods.

private void ActivateColorProtection_Clicked(object sender, EventArgs e)
{
#if IOS
    _screenSecurity.EnableColorScreenProtection("#6C4675");
#endif
}

private void DeactivateColorProtection_Clicked(object sender, EventArgs e)
{
#if IOS
    _screenSecurity.DisableColorScreenProtection();
#endif
}
Image Screen Protection

To utilize this method, please follow these steps:

  • Save the image you intend to use inside the Resources\Images folder.
  • Ensure you refer to the .Net MAUI Image documentation for detailed instructions on how to accomplish this task effectively.

⚠️ If your app does not recognize the image after setting the build action to MauiImage, consider changing the build action to Embedded resource to ensure proper functionality.

/// <param name="image">Name with extension of the image to use.</param>
/// <remarks>Supported for iOS only.</remarks>
void EnableImageScreenProtection(string image);

This method safeguards screen content from exposure by utilizing an Image when the app is sent to Background or displayed on the App Switcher.

The image property, which accepts a string argument, should contain the name of the image file along with its extension.

If the method fails, a message will be displayed on the Console and no Exepction will be thrown.

/// <remarks>Supported for iOS only.</remarks>
void DisableImageScreenProtection();

This method removes the Image and re-enables screen content exposure.

If the method fails, a message will be displayed on the Console and no Exepction will be thrown.

Example

This method can also be attached to a single page by using it on the OnAppearing and OnDisappearing methods.

protected override void OnAppearing()
{
    base.OnAppearing();
#if IOS
    _screenSecurity.EnableImageScreenProtection("protection_bg.png");
#endif
}

protected override void OnDisappearing()
{
#if IOS
    _screenSecurity.DisableImageScreenProtection();
#endif
    base.OnDisappearing();
}
Screen Recording Protection
/// <param name="withColor">Hexadecimal color as string in the form of #RGB, #RGBA, #RRGGBB or #RRGGBBAA. 
/// It can be mixed with withBlur param.</param>
/// <param name="withBlur">Set it to false to deactivate screen protection with Blur. It can be mixed with withColor param. True by default.</param>
/// <remarks>Supported for iOS only.</remarks>
void EnableScreenRecordingProtection(string withColor, bool withBlur);

This method effectively prevents screen content from being recorded by the system or any external application, utilizing a default Blur layer.

The withColor property allows you to specify a color argument in the form of #RGB, #RGBA, #RRGGBB, or #RRGGBBAA. By default, this feature is disabled.

The withBlur property is used to enable a blur layer with a Light theme, which is active by default. If desired, you can set it to false to disable the blur layer.

⚠️ If a screen recording has already started before calling this method, the screen content will be exposed in the recorded film.

If the method fails, a message will be displayed on the Console and no Exepction will be thrown.

/// <remarks>Supported for iOS only.</remarks>
void DisableScreenRecordingProtection();

This method will turn off the screen recording protection.

If the method fails, a message will be displayed on the Console and no Exepction will be thrown.

Example

This method can also be attached to a single page by using it on the OnAppearing and OnDisappearing methods.

private async void ActivateRecordingProtection_Clicked(object sender, EventArgs e)
{
#if IOS
    _screenSecurity.EnableScreenRecordingProtection();
#endif
}

private async void DeactivateRecordingProtection_Clicked(object sender, EventArgs e)
{
#if IOS
    _screenSecurity.DisableScreenRecordingProtection();
#endif
}

Usage

public partial class MainPage : ContentPage
{
    public MainPage()
    {
        InitializeComponent();
    }

    protected override void OnAppearing()
    {
        base.OnAppearing();
#if ANDROID
        _screenSecurity.EnableScreenSecurityProtection();
#elif IOS
        _screenSecurity.EnableBlurScreenProtection(ThemeStyle.Light);
        _screenSecurity.EnableScreenRecordingProtection();
#endif
    }

    protected override void OnDisappearing()
    {
#if ANDROID
        _screenSecurity.DisableScreenSecurityProtection();
#elif IOS
        _screenSecurity.DisableBlurScreenProtection();
        _screenSecurity.DisableScreenRecordingProtection();
#endif
        base.OnDisappearing();
    }
}

Sample

Please refer to the ScreenSecuritySample for a comprehensive and detailed implementation of this plugin, providing you with a complete understanding of its usage.

Contributions

Please feel free to open an Issue if you encounter any bugs or submit a PR to contribute improvements or fixes. Your contributions are greatly appreciated.

License

Plugin.Maui.ScreenSecurity is licensed under MIT.

Product Compatible and additional computed target framework versions.
.NET net6.0-android31.0 is compatible.  net6.0-ios16.1 is compatible.  net6.0-windows10.0.19041 is compatible.  net7.0-android was computed.  net7.0-android33.0 is compatible.  net7.0-ios was computed.  net7.0-ios16.1 is compatible.  net7.0-windows was computed.  net7.0-windows10.0.19041 is compatible.  net8.0-android was computed.  net8.0-ios was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0-android31.0

    • No dependencies.
  • net6.0-ios16.1

  • net6.0-windows10.0.19041

    • No dependencies.
  • net7.0-android33.0

    • No dependencies.
  • net7.0-ios16.1

    • No dependencies.
  • net7.0-windows10.0.19041

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.0 1,399 10/14/2024
1.1.8-beta 2,303 5/25/2024
1.1.7-beta 4,210 5/19/2024
1.1.6 10,444 3/18/2024
1.1.5 5,869 10/24/2023
1.1.0 2,263 7/21/2023
1.0.7-beta 137 7/18/2023
1.0.6-beta 138 7/18/2023
1.0.5-beta 145 7/17/2023 1.0.5-beta is deprecated because it has critical bugs.
1.0.4-beta 118 7/12/2023
1.0.3-beta 126 7/9/2023
1.0.0 778 5/19/2023