在 React Native App 中禁用屏幕截图/屏幕截图 [英] Disable Screen Capture/ScreenShot in React Native App

查看:68
本文介绍了在 React Native App 中禁用屏幕截图/屏幕截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了一些特定于 ios 和 Android 的解决方案,以防止截屏和截屏.但是如何在 React Native 中禁用屏幕捕获?

I have came across few solutions specific for ios and Android to prevent screen-capturing and taking screenshots. But how do i disable screen-capturing in react native?

推荐答案

Android

/android/app/src/main/java/com/{Project_Name}/MainActivity.java

您可以添加以下几行.通过 setFlag FLAG_SECURE 防止截屏,以下面的代码为例:

you may add the following lines. Prevent capture screen by setFlag FLAG_SECURE, use code below as an example:

import android.os.Bundle;
import android.view.WindowManager;

...

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
}

稍后当您要删除安全标志时

later when you want to remove secure flag

getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);

iOS

AppDelegate.m中叠加屏幕,以这个例子:

iOS

overlay screen in AppDelegate.m, take this example:

- (void)applicationWillResignActive:(UIApplication *)application {    
    // fill screen with our own colour
    UIView *colourView = [[UIView alloc]initWithFrame:self.window.frame];
    colourView.backgroundColor = [UIColor whiteColor];
    colourView.tag = 1234;
    colourView.alpha = 0;
    [self.window addSubview:colourView];
    [self.window bringSubviewToFront:colourView];
    // fade in the view
    [UIView animateWithDuration:0.5 animations:^{
        colourView.alpha = 1;
    }];
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // grab a reference to our coloured view
    UIView *colourView = [self.window viewWithTag:1234];
    // fade away colour view from main view
    [UIView animateWithDuration:0.5 animations:^{
        colourView.alpha = 0;
    } completion:^(BOOL finished) {
        // remove when finished fading
        [colourView removeFromSuperview];
    }];
}

这篇关于在 React Native App 中禁用屏幕截图/屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆