ios - 如何在 Flutter 中限制 iOS 设备的屏幕录制?
问题描述
我正在 Flutter 中开发一个应用程序,我需要限制 iOS 设备中的屏幕录制。我现在所做的是检查 AppDelegate 中的 UIScreen.main.isCaptured 标志,并使用我的 dart 文件中的计时器经常检查它。
有没有更好的方法通过使用来自苹果的 captureDidChangeNotification 来做到这一点,这样我就不必运行计时器并且当屏幕录制状态发生变化时 dart 文件会得到通知?
解决方案
您在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 。镖
推荐阅读
- maven - H2-数据库异常“引起:org.h2.jdbc.JdbcSQLException:找不到序列“SYSTEM_SEQUENCE_*”;” 在运行 Junit 测试用例时
- reactjs - 无法通过 prevState 更新响应中的表单字段
- c# - 无法从程序集中加载类
- c - Netbeans 调试器(用于 Linux-C 开发)在 waitpid 期间/之后终止(不打断点)
- android - 事件总线粘性事件
- php - 如何定义一个模板函数,然后在模板中我可以调用它
- java - Zookeper GC 按日期和大小滚动
- php - 用户在php中登录时从用户名中删除空格
- jquery - 在 typescript 中导入 unitegallery.min.js 时未定义 jQuery
- typescript - 请解释 TypeScript 中的 ... 运算符