capacitor-community / privacy-screen

⚡️ Capacitor plugin that protects your app from displaying a screenshot in Recents screen/App Switcher.
MIT License
87 stars 23 forks source link

bug: disable method does not work on iOS #82

Closed Phil0x11 closed 8 months ago

Phil0x11 commented 1 year ago

Plugin version: 4.2.1

Platform(s): iOS

Current behavior: If I call the disable method the privacy screen will not be disabled in screenshots. I am still not able to screenshot the app.

Expected behavior: After calling the disable method, the privacy screen will be disabled.

Steps to reproduce:

  1. Clone example github repo
  2. Build code on iOS device
  3. Screenshot App --> Working
  4. Click on "Enable Privacy Screen" --> Working (screenshot does not work)
  5. Click on "Disable Privacy Screen" --> Not working (screenshot still does not work)

Related code: https://github.com/Phil0x11/capacitor-privacy-screen-test

Capacitor doctor: Latest Dependencies:

@capacitor/cli: 5.5.1 @capacitor/core: 5.5.1 @capacitor/android: 5.5.1 @capacitor/ios: 5.5.1

Installed Dependencies:

@capacitor/android: not installed @capacitor/cli: 5.5.1 @capacitor/core: 5.5.1 @capacitor/ios: 5.5.1

robingenz commented 1 year ago

Unfortunately there are several problems with the screenshot feature. I may revert it (see https://github.com/capacitor-community/privacy-screen/issues/76#issuecomment-1776551316). However, PRs are welcome.

mfinity168 commented 1 year ago

I encountered the same problem. Can't use disable().
My install packages on capacitor js.

"@capacitor-community/privacy-screen": "4.2.2", "@capacitor/android": "5.5.1", "@capacitor/cli": "5.5.1", "@capacitor/core": "5.5.1", "@capacitor/ios": "5.5.1",

please resolve problem

Thanks

Phil0xFF commented 1 year ago

I looked a little bit into that issue. It seems not all secure UITextField get removed on calling the enableScreenshots method. I did not found a way to fix that yet.

jkyoutsey commented 1 year ago

What would the effect of reverting your last change be? Would it just stop working all together, or...? I see the same issue that disable doesn't work on iOS and that's quite a blocker at this point.

robingenz commented 1 year ago

What would the effect of reverting your last change be?

Screenshots would no longer be prevented under iOS.

taitems commented 11 months ago

I'd be happy with removing the prevention on iOS, I'm more interested in event capture. Or even if you forked the plugin?

rogomez-pricesmart commented 9 months ago

For some reason when the for of self.subviews, the items that are returned are not of type UITextField, I have a small modification and it seems to work, first I declare a secureTextFields variable of type array, and then in the addSecureText function I make an append field to the variable, and then when the enableScreenshots function is called it cycles through the array and not self.subviews, I attach screen I hope to help thanks

swift
tafelnl commented 8 months ago

@rogomez-pricesmart Tested your solution, seems to work perfectly fine indeed! I'm curious if this approach could potentially cause memory leaks. I'm not very experienced with Swift, so I have no idea.

BTW: First of all thank you very much for your input! Secondly: never, ever share code by means of a screenshot ;) Just paste it as text or create a PR

jonas-elias commented 8 months ago

For some reason when the for of self.subviews, the items that are returned are not of type UITextField, I have a small modification and it seems to work, first I declare a secureTextFields variable of type array, and then in the addSecureText function I make an append field to the variable, and then when the enableScreenshots function is called it cycles through the array and not self.subviews, I attach screen I hope to help thanks

swift

It appears that the modification you made, where you declare a separate array secureTextFields to store the secure text fields and append to it in the addSecureText function, is causing a memory leak issue.

The reason for this memory leak is that when you append newField to secureTextFields, you're holding a strong reference to newField within the array. If you don't manage these references properly, it can lead to retain cycles, where objects reference each other and cannot be deallocated even when they are no longer needed.

To resolve this memory leak, you need to ensure that you properly manage the lifecycle of the UITextField instances stored in secureTextFields. This could involve removing references to them when they are no longer needed, such as when the corresponding view is removed from the superview or when the text fields themselves are deallocated.

Check pull request mention 😎🌷