简体   繁体   中英

How to restrict screen recording in iOS devices in Flutter?

I am developing an app in Flutter, which I need to restrict screen recording in iOS devices. What I have done now is checking for the UIScreen.main.isCaptured flag in the AppDelegate and checking it frequently using a timer in my dart file.

Is there a better way to do this by making use of capturedDidChangeNotification from apple, so that I don't have to run a timer and the dart file get notified when the screen recording status changes?

You add capturedDidChangeNotification observer on NotificationCenter and push the result to FlutterEventChannel. Then on Dart side you setup EventChannel , which has receiveBroadcastStream method that returns a Stream than you can listen to. To be sure to handle closing Streams both on iOS part and Flutter.

You can checkout these official example with listening to battery charging, which is almost the same (NotificationCenter + Streams):

https://github.com/flutter/flutter/blob/master/examples/platform_channel_swift/ios/Runner/AppDelegate.swift https://github.com/flutter/flutter/blob/master/examples/platform_channel_swift/lib/main.dart

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM