macos-big-sur - AXObserverAddNotification 在 Big Sur OSX 11.5 中失败
问题描述
用最新的 11.5 更新替换 Big Sur MacOS 11.0 后,尽管提供了观察者和元素,但我的应用程序的 AXObserverAddNotification 方法失败了。下面是我使用的 ObjC 代码:
if (AXObserverCreate(pid, menuOpened, &observer) == kAXErrorSuccess) {
CFRunLoopAddSource(CFRunLoopGetCurrent(),
AXObserverGetRunLoopSource(observer),
kCFRunLoopDefaultMode);
AXUIElementRef element = AXUIElementCreateApplication(pid);
NSLog(@"observer: %@ element: %@", observer, observer);
if(AXObserverAddNotification(observer, element, kAXMenuOpenedNotification, (__bridge void *)(self)) != kAXErrorSuccess) {
NSLog(@"Failed to create observer for application \"%@\". pid: %i", self.activeApp, pid);
}
}
以下是日志窗口输出,显示 AXObserverAddNotification 方法“无法为新启动的应用程序创建观察者”——在本例中为“系统偏好设置”:
2021-08-11 10:59:52.682012-0700 SpellSentry[98563:3551301] 观察者:<AXObserver 0x6000032d21c0> {pid=98580} 元素:<AXObserver 0x6000032d21c0> {pid=98580} 05521-02.6951: -0700 SpellSentry[98563:3551301] 无法为应用程序“系统偏好”创建观察者。PID:98580
我从未在 MacOS 11.0 中遇到过这个错误,并且怀疑较新的操作系统包含额外的安全措施,这些措施会干扰 Carbon 层(“可访问性”编程层)的正常运行。也许其他人对 OSX 11.5 也有同样的问题?还是我?
解决方案
推荐阅读
- plugins - Gatsby 教程第 3 部分:无法使用排版插件
- flutter - 如何从 DART / Flutter 中的数组中获取按天分组的每天值的总和?
- r - R:R 中有 pandas 函数映射吗?
- javascript - 文本框未通过复选框单击隐藏(javascript)
- python - 复杂的 JSON,如何获得价值?
- blazor - 基本组件布局继承 blazor
- excel - 安全删除未使用的编码:可以调用宏的所有方法是什么?
- r - 如何根据分号分隔列中的值过滤行?
- angular - Angular - 覆盖(仅)环境的一个属性
- spring-boot - Spring Boot Starter Data JPA - liquibase 错误