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

Version 1.2.1 problem #6

Closed Simimi-dot closed 5 months ago

Simimi-dot commented 7 months ago

When installing version 1.2.1, the View is no longer visible on the simulator, preview, or real device; it is painted white Simulator Screenshot - iPhone 15 Pro - 2024-02-21 at 22 04 19

JayantBadlani commented 7 months ago

@Simimi-dot, have you tried running the provided example project on the real device? Is it the same there?

I just tried it and it's working fine for me. https://github.com/JayantBadlani/ScreenShield/assets/37996543/e0d6edd7-052b-4c0b-99ee-ea00b0aaf435

Simimi-dot commented 7 months ago

@JayantBadlani Yes, I immediately updated and installed it, and on the preview and on the simulator and on the real View device they are painted white. I tested on iOS 17.2

JayantBadlani commented 7 months ago

@Simimi-dot, I'm unable to reproduce your issue. The screen recording I shared is also from iOS 17.2. Please provide your example project or file so I can replicate it on my end.

Simimi-dot commented 7 months ago
.protectScreenshot()
.onAppear(perform: {
            ScreenShield.shared.protectFromScreenRecording()
        })

I tested the problem and discovered that it turns out that this code cannot be attached to internal views, because of this everything breaks. You can use these modifiers only on the outermost view in the hierarchy on the screen, for example:

so everything works fine

var body: some View {
        TabView(selection: $currentTab) {
            ForEach(0..<3, id: \.self) { indexOfPlayer in
                TestSoloVideo(videoStringURL: recipeURL)
            }
        }
        .overlay(alignment: .bottom) {
            HStack {
                ForEach(0..<3, id: \.self) { indexOfPage in
                    Circle()
                        .fill(currentTab == indexOfPage ? Color.white : Color.gray)
                        .frame(width: 10, height: 10)
                }
            }
        }
        .tabViewStyle(.page(indexDisplayMode: .never))
        .frame(width: 375, height: 230)
        .clipShape(RoundedRectangle(cornerRadius: 25))
        .shadow(color: .black, radius: 4, y: 5)
        .protectScreenshot()
        .onAppear(perform: {
            ScreenShield.shared.protectFromScreenRecording()
        })
    }

and now everything is breaking down

var body: some View {
        TabView(selection: $currentTab) {
            ForEach(0..<3, id: \.self) { indexOfPlayer in
                TestSoloVideo(videoStringURL: recipeURL)
                    .protectScreenshot()
                    .onAppear(perform: {
                        ScreenShield.shared.protectFromScreenRecording()
                    })
            }
        }
        .overlay(alignment: .bottom) {
            HStack {
                ForEach(0..<3, id: \.self) { indexOfPage in
                    Circle()
                        .fill(currentTab == indexOfPage ? Color.white : Color.gray)
                        .frame(width: 10, height: 10)
                }
            }
        }
        .tabViewStyle(.page(indexDisplayMode: .never))
        .frame(width: 375, height: 230)
        .clipShape(RoundedRectangle(cornerRadius: 25))
        .shadow(color: .black, radius: 4, y: 5)
    }

Perhaps I missed something from the description