Web Analytics
Skip to main content

initSettings NEW ✨

Version

Available from v2.0.0+

Initialize ScreenGuard with your desired settings. This function must be called before using any other ScreenGuard API.

Parameters

Accepted a JS object with following parameters:

NameRequiredTypeDefault
enableCaptureNobooleanfalse
enableRecordNobooleanfalse
enableContentMultitaskNobooleanfalse
displayScreenGuardOverlayNobooleanfalse
displayScreenguardOverlayAndroidNobooleantrue
timeAfterResumeNonumber1000
getScreenshotPathNobooleanfalse
limitCaptureEvtCountNonumbernull
trackingLogNobooleanfalse

enableCapture

Typeboolean
Defaultfalse
PlatformiOS, Android

Enable to allow screenshot or disable it. Default is false (disabled).


enableRecord

Typeboolean
Defaultfalse
PlatformiOS 13+, Android 15+ (API 35+)

Enable to allow screen recording or disable it. Default is false (disabled).

Android limitation

Screen recording detection on Android is only available on API 35+ (Android 15+). On older versions, this setting is ignored.


enableContentMultitask

Typeboolean
Defaultfalse
PlatformiOS only

When set to true, your app content will remain visible in the App Switcher (multitasking view), and hidden/blurred based on the register type (color, blur, or image) when false.


displayScreenGuardOverlay

Typeboolean
Defaultfalse
PlatformiOS only

When set to true, displays an overlay when user screenshot or screen record (show until user stop recording) and disapears after a duration of timeAfterResume. The overlay uses the same style as your registered (color, blur, or image).

Note: Use if is not affecting your app's functionality, and use at your own risk!


displayScreenguardOverlayAndroid

Typeboolean
Defaulttrue
PlatformAndroid only

When set to true, displays an overlay when user returns to the app from background. Default is true (enabled).


timeAfterResume

Typenumber (milliseconds)
Default1000
PlatformiOS, Android

Duration in milliseconds to display the overlay after capture (iOS) or after returning from background (Android). Required displayScreenGuardOverlay or displayScreenguardOverlayAndroid to be true.

Example: Set to 2000 for a 2-second overlay display.


getScreenshotPath

Typeboolean
Defaultfalse
PlatformiOS, Android

When set to true, the screenshot event data will include the file path to the captured screenshot.

Related: useSGScreenShot hook's screenshotData.path property.


limitCaptureEvtCount

Typenumber | null
Defaultnull
PlatformiOS, Android*

Limit the number of screenshot capture events triggered.

  • null or 0: Trigger every time (unlimited)
  • > 0: Only trigger for the first N screenshots
Android limitation

On Android, screenshot detection may not work while screenguard is active (FLAG_SECURE blocks standard screenshot attempts).

Related: Works with useSGScreenShot hook.


trackingLog

Typeboolean
Defaultfalse
PlatformiOS, Android

Enable activity logging for debugging purposes. When enabled, ScreenGuard will record all events (activate, deactivate, screenshot detected, etc.).

Related: Use getScreenGuardLogs to retrieve recorded logs.


Example code

Basic initialization:

import ScreenGuardModule from 'react-native-screenguard';

// Initialize with default settings
await ScreenGuardModule.initSettings();

With custom settings:

import ScreenGuardModule from 'react-native-screenguard';

await ScreenGuardModule.initSettings({
displayScreenGuardOverlay: true,
timeAfterResume: 2000,
getScreenshotPath: true,
trackingLog: true,
});
Important
  • You must call initSettings() before calling any register* function, otherwise an error will be thrown.
  • Always call this function at the app entry point (e.g., App.tsx or index.js).

Demo