如何在macOS中请求可访问性权限 [英] How to ask for Accessibility permission in macOS

查看:186
本文介绍了如何在macOS中请求可访问性权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于Mojave没有可访问性权限,因此以下代码不起作用

KeyMap keyStatesBig;GetKeys(keyStatesBig);

但是是否有钥匙可以放入info.plist来询问用户启动应用的权限?

解决方案

info.plist 不可能.

您可以在启动时自行询问用户.使用

(如上所述, Turn on Accessibility 按钮只是将系统偏好设置"打开到正确的位置)

The below code doesn't work since Mojave without Accessibility permission

KeyMap keyStatesBig; GetKeys(keyStatesBig);

But is there a key to put in info.plist to ask users permission on app launch?

解决方案

It's not possible with the info.plist.

You can ask the user yourself, on startup. Use AXIsProcessTrusted to determine whether accessibility is enabled or not.

If it's not enabled, you can show a dialog asking the user to switch it on.

You can open the relevant preferences for the user also:

NSString* prefPage = @"x-apple.systempreferences:com.apple.preference.security?Privacy_Accessibility";
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:prefPage]];

See how Dropbox does it (this is custom UI):

(The Turn on Accessibility button simply opens the System Preferences to the correct place, as mentioned above)

这篇关于如何在macOS中请求可访问性权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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