Flutter Ios prevent screenshot

776 Views Asked by At

I'm blocking screenshots and video records for ios in my app. But when I installed the latest update ios rejected it.

We noticed that your app shows a custom screenshot-initiated interface when the user takes a screenshot, but the interface duplicates the iOS system-provided screenshot interface and functionality.

Duplicating system-provided interfaces does not provide the simple, innovative, and easy to use experience App Store users expect.

This is rejected message.

This is my code

      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)
    }
  }

How to I solve it

2

There are 2 best solutions below

0
On

Now there's an opportunity to block screen recording in iOS through flutter plugin.

For iOS:

  1. add the flutter plugin called flutter_prevent_screen_capture to your

pubspec.yaml

then run flutter pub get.

  1. Define variables like below:
///Define a streamSubscription in order to receive changes
  late StreamSubscription<bool> _screenRecordsSubscription;

  ///Get the instance of plugin for multiple use.
  FlutterPreventScreenCapture preventScreenCapture =
      FlutterPreventScreenCapture();

  ///is Recording is set to false initially.
  bool isRecording = false;

  1. initialize variables in initstate method:
updateRecordStatus(bool record) {
   isRecording = record;
   setState(() {});
 }

@override
 void initState() {
   ///Though listening to the screen record, it is recommended to check the screen record status on the first launch.
   checkScreenRecord();

   ///Initialize screenRecordSubscription to regularly listen to the changes
   _screenRecordsSubscription =
       preventScreenCapture.screenRecordsIOS.listen(updateRecordStatus);
   super.initState();
 }

So you can listen to the screen recording status.

If you want to check the screen recording status once:

 Future<void> checkScreenRecord() async {
    final recordStatus = await preventScreenCapture.checkScreenRecord();

    debugPrint('Is screen being recorded: $recordStatus');

    isRecording = recordStatus;
    setState(() {});
  }

The last thing is don't forget to cancel subscription in dispose method:

@override
  dispose() {
    _screenRecordsSubscription.cancel();
    super.dispose();
  }
2
On

I've the same problem. Apple says that:

"We noticed that your app shows a custom screenshot-initiated interface when the user takes a screenshot, but the interface duplicates the iOS system-provided screenshot interface and functionality.

Specifically, your app only displayed a black blank page when the user takes a screenshot.

Duplicating system-provided interfaces does not provide the simple, innovative, and easy to use experience App Store users expect.

To resolve this issue, either remove the custom interface or revise it to not duplicate the system-provided screenshot interface and functionality."