LoginSignup
3
1

More than 1 year has passed since last update.

ReactNativeでスクリーンショットを禁止する

Posted at

詳細については後ほど記載していく。
先に結論のみ。

iOS

1)スクリーンショット禁止処理を実装(UIViewやUIWindowのExtention)
2)AppDelegate.mや任意の処理で呼び出し
参考

extension UIWindow {
    func makeSecure() {
        let field = UITextField()
        field.isSecureTextEntry = true
        self.addSubview(field)
        field.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true
        field.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true
        self.layer.superlayer?.addSublayer(field.layer)
        field.layer.sublayers?.first?.addSublayer(self.layer)
    }
}

Android

1)MainActivityなどで以下処理を追記

getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);

2)解除したい場合は以下を呼び出す処理をReactNativeから呼び出せるようにすれば良い。

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

参考

参考にした記事一覧

--【iOS】---------------
・サンプルPJ
https://github.dev/mittsu333/SecureScreen
・Swiftで定義したExtensionをObjective-Cで利用(Objective-C)
https://komaji504.hateblo.jp/entry/2016/07/18/213933
 →上記をObjective-Cで書き直すには
 https://komaji504.hateblo.jp/entry/2016/07/18/213933
・Objective-Cでメソッドを呼出(Objective-C)
https://qiita.com/Pinehead/items/a9476dcac6e39f33c282
・AppDelegateで関数呼出(Flutter Objective-C)
https://stackoverflow.com/questions/52317217/flutter-disable-screenshot-capture-for-app
・スクリーンショット禁止処理(Swift Extension)
https://stackoverflow.com/questions/18680028/prevent-screen-capture-in-an-ios-app

--【Android】---------------
https://qiita.com/tkhs0604/items/47bfa0f2b83b79c365e4
https://stackoverflow.com/questions/28606689/how-to-prevent-screen-capture-in-android
https://stackoverflow.com/questions/6764568/prevent-screen-capture-in-android-apps

--【Swift】---------------
https://github.dev/lizhming/ScreenCaptureSecure/

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1