首页 > 解决方案 > 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 也有同样的问题?还是我?

标签: macos-big-suruiaccessibility

解决方案


推荐阅读