macos - 在 Catalina (kCGWindowName) 中启用屏幕录制 API
问题描述
以下代码在 Mojave 中运行良好。
let options = CGWindowListOption(arrayLiteral: CGWindowListOption.excludeDesktopElements, CGWindowListOption.optionOnScreenOnly, CGWindowListOption.optionOnScreenAboveWindow)
let windowList = CGWindowListCopyWindowInfo(options, kCGNullWindowID) as NSArray? as? [[String: AnyObject]]
for entry in windowList!
{ let name = (entry[kCGWindowName as String] != nil) ? entry[kCGWindowName as String] as! String : ""
...
在卡塔利娜
entry[kCGWindowName as String]
总是零
在 SO:Detecting screen recording settings on macOS Catalina我读过,这不是启用“屏幕录制 API”以及如何检测(如果已启用)所必需的。
不幸的是,我不知道如何启用“屏幕录制 API”。
如 SO:macOS Catalina 屏幕录制权限中所述,我打开了自动代码签名。
在系统偏好设置中,我看不到“+”来添加应用程序,以授予“屏幕录制”。
如何授予录屏 API 权限?
解决方案
This a low level api to request access to screen recording. Calling this functions will present a prompt to give access for screen recording.
/* Requests event listening access if absent, potentially prompting */
@available(macOS 10.15, *)
public func CGRequestScreenCaptureAccess() -> Bool
推荐阅读
- asp.net-core - ASP.NET Core 中的 TraceId、RequestId 和 TraceIdentifier
- .net - 点网单元测试框架工具,用于在点网源代码上自动生成单元测试方法
- javascript - 模态不使用道具关闭
- matlab - 从命令行调用 Matlab 会遇到未知类型的意外异常,为什么?
- c# - 结合字符串中的日期和时间并转换为日期时间
- r - 将列表列表传递给函数的正确方法,缺少和/或不相关的元素
- rust - 映射数字范围 Rust
- plot - 如何限制以前的情节?
- database - 从 AB BA 中删除重复数据
- spring - MockMvc WebMvcTests Spring Hateoas 返回多个 NestedLinks