如何使用Swift访问MacOSX Cocoa应用程序中的辅助功能设置? [英] How to access accessibility settings in MacOSX Cocoa app using swift?

查看:310
本文介绍了如何使用Swift访问MacOSX Cocoa应用程序中的辅助功能设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很困惑.通常在iOS应用中,我会使用url方案访问设置.现在,我发现在MacOSX上使用Objective-C可以做到这一点:

I'm pretty confused. Usually in an iOS app I would access the settings using a url scheme. Now I found out that on MacOSX using Objective-C you can do this:

    NSDictionary *options = @{(id)kAXTrustedCheckOptionPrompt: @YES};
    BOOL accessibilityEnabled = AXIsProcessTrustedWithOptions((CFDictionaryRef)options);

我尝试将其转换为Swift,但没有得到有效的结果. 有人知道如何转换此方法或有效方法来请求Swift中的辅助访问吗?

I've tried to convert this to Swift but didn't got to a valid result. Does anyone know how to convert this or a valid method to ask for assistive access in Swift?

推荐答案

kAXTrustedCheckOptionPrompt类型为Unmanaged<CFString>,因此您需要访问如下所示的保留值

The kAXTrustedCheckOptionPrompt type is Unmanaged<CFString> so you need to access to the retained value as show below

let options : NSDictionary = [kAXTrustedCheckOptionPrompt.takeRetainedValue() as NSString: true]
let accessibilityEnabled = AXIsProcessTrustedWithOptions(options)

这篇关于如何使用Swift访问MacOSX Cocoa应用程序中的辅助功能设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆