1

SwiftUI has a SecureField text field which doesn't show anything typed into it when viewed from screen recordings or screenshots. Similarly, iOS 15 is going to have a .privacySensitive() modifier that removes the View from widgets and such. Does anyone have any idea on how to implement Views like this? I want a View which blurs itself when it's contained in screen recordings, screenshots, app widgets, multitasking menu (so they can't cheat the system) etc.

Any suggestions on how to achieve this effect would be greatly appreciated.

Thanks in advance!

Edit: You can tell if someone has opened the multitasking menu by subscribing to NotifcationCenter.default.publisher(for: UIApplication.willResignActive, perform: { _ in }). However I still haven't been able to figure out the others

Edit 2: I also found that subscribing to UIScreen.capturedDidChangeNotification tells you if screen recording is active. Still stuck on screenshots and widgets

rayaantaneja
  • 1,182
  • 7
  • 18

1 Answers1

0

I'm not so sure if you can hide screenshots because UIApplication only has a .userDidTakeScreenshotNotification Notification Name. If you are trying to do it manually rather than using iOS 15s .privacySensitive(), you can overlay a View over the entire app. To do this, as you stated you could use the UIApplication.willResignActive to overlay such a view in the Multitasking menu.

To achieve this however you need to get the window and add the subview to it as follows

let currentWindow: UIWindow? = UIApplication.shared.keyWindow
currentWindow?.addSubview(myOverlayView)

For the screenshot problem, like I stated above, Swift only has a .userDidTakeScreenshotNotification and no .userWillTakeScreenshotNotification. So the best bet is to delete the last image by listening to the screenshot notification. You can see how to delete the last photo of the gallery here. This should provide the delete for all feature Whatsapp seems to use. Given that, you will still have to provide access to the gallery

This should give you something similar to the snapchat app. This code is not tested

Visal Rajapakse
  • 1,718
  • 1
  • 9
  • 15
  • Yeah I managed to figure out the multitasking and screen recording bits. I'm still figuring out the screenshot one. Let me know if you have any ideas. – rayaantaneja Jul 17 '21 at 16:52
  • I think the image will still be in "Recently Deleted". Can we delete images from there as well? – rayaantaneja Jul 17 '21 at 17:54