JayantBadlani / ScreenShield

ScreenShield is an iOS library that provides a simple way to protect your app's content from being captured or recorded by screenshots, screen recordings, or other screen capture methods. It works by adding a secure layer on top of your views, which prevents most screen capture mechanisms from recording the underlying content.
MIT License
89 stars 15 forks source link

React Native screen shield returning null #14

Closed NaserAlqimlas closed 2 months ago

NaserAlqimlas commented 3 months ago

I have followed the steps in the readme to implement the library using react native but the ScreenShieldRN native event is returning null.

using React Native 0.71.6

Here is my code

ScreenShieldRNBridge.h

#import <React/RCTBridgeModule.h>
#import <React/RCTViewManager.h>

ScreenShieldRN.swift

import Foundation
import ScreenShield

@objc(ScreenShieldRN)
class ScreenShieldRN: NSObject {

    @objc func protectScreenRecording() {
        ScreenShield.shared.protectFromScreenRecording()
    }

    @objc static func requiresMainQueueSetup() -> Bool {
        return true
    }
}

ScreenShieldRN.m

#import <Foundation/Foundation.h>
#import <React/RCTBridgeModule.h>
#import "React/RCTLog.h"

@interface RCT_EXTERN_MODULE(ScreenShieldRN, NSObject)

RCT_EXTERN_METHOD(protectScreenRecording)

@end

MainComponent.js

import {NativeModules} from 'react-native';

function MainComponent (props) {
  const {ScreenShieldRN} = NativeModules;
  ScreenShieldRN.protectScreenRecording();
}
...
JayantBadlani commented 3 months ago

Hi @gulsher7,

Could you please assist @NaserAlqimlas with this issue?

Thank you!

Keatooon commented 3 months ago

HI @NaserAlqimlas did you managed to resolve it? mind to share it here as well please?

@gulsher7 able to help please? I'm able to get the detect and block screenrecording. But how to block screenshot? Would like to block all the screen in react-native app, perhaps need to add it in AppDelegate.m? (or block screenshot works with SwiftUI only?)

I2C-RoyYou commented 2 months ago

I have same problem here ,is anyone has a solution?

I2C-RoyYou commented 2 months ago

@NaserAlqimlas : Hi , I've resolve this question, you need to build .h .m by Xcode , not create file by editor like visual studio, I create swift, .h , .m files by Xcode, now work!

richardo2016x commented 2 months ago

@JayantBadlani Hi, most of React Native developers who were used to writing pure JavaScript, and have no any Native(Swift/Objective-C) Coding experience, so they'd like to Create files directly rather than creating them in XCode, and don't know add those files into projects. What they should do to fix error is just:

image

Maybe it's better to clarify it in README: user must make sure xcode embed the files they created.

JayantBadlani commented 2 months ago

Hi @richardo2016x

Thanks for letting me know! If you want to fork and raise a merge request with an updated README, I’d be happy to merge it and welcome you as a contributor.

JayantBadlani commented 2 months ago

Hi @richardo2016x, I have updated the README file as per your recommendation. Could you please take a look and verify? Thanks!

richardo2016x commented 2 months ago

Hi @richardo2016x, I have updated the README file as per your recommendation. Could you please take a look and verify? Thanks!

Hi @JayantBadlani , it's nice of you to reply me and do the changes on README.md. Based on your changes, I add more details about "How to create or add files in Xcode IDE" for those developers who're not familar with Xcode, the PR(https://github.com/JayantBadlani/ScreenShield/pull/17) is here: https://github.com/JayantBadlani/ScreenShield/pull/17

JayantBadlani commented 2 months ago

Hi @richardo2016x,

I have merged your PR(https://github.com/JayantBadlani/ScreenShield/pull/17) Thank you for your contribution and adding the additional details. Your input is much appreciated!