首页 > 解决方案 > 如何在 Flutter 中限制 iOS 设备的屏幕录制?

问题描述

我正在 Flutter 中开发一个应用程序,我需要限制 iOS 设备中的屏幕录制。我现在所做的是检查 AppDelegate 中的 UIScreen.main.isCaptured 标志,并使用我的 dart 文件中的计时器经常检查它。

有没有更好的方法通过使用来自苹果的 captureDidChangeNotification 来做到这一点,这样我就不必运行计时器并且当屏幕录制状态发生变化时 dart 文件会得到通知?

标签: iosswiftflutter

解决方案


您在NotificationCenter上添加capturedDidChangeNotification观察者并将结果推送到 FlutterEventChannel。然后在 Dart 端设置EventChannel,它具有返回 Stream 的方法,而不是您可以收听的。确保在 iOS 部分和 Flutter 上处理关闭 Streams。receiveBroadcastStream

您可以通过收听电池充电来查看这些官方示例,几乎相同(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 。镖


推荐阅读