How to grant Accessibilty access in Xcode

倾然丶 夕夏残阳落幕 提交于 2020-01-16 09:01:28

问题


I'm struggling to get Accessibility permission in Xcode.

I have the following (working) code:

 func checkAccess() -> Bool{
    //get the value for accesibility
    let checkOptPrompt = kAXTrustedCheckOptionPrompt.takeUnretainedValue() as NSString
    //set the options: false means it wont ask
    //true means it will popup and ask
    let options = [checkOptPrompt: true]
    //translate into boolean value
    let accessEnabled = AXIsProcessTrustedWithOptions(options as CFDictionary?)

    if accessEnabled == true {
        print("Access Granted")
        label.stringValue = "Access Granted"
    } else {
        print("Access not allowed")
        label.placeholderString = "Access not allowed"
        label.stringValue = "Access not allowed"
    }

    return accessEnabled
}

When building and running the app in Xcode, AXIsProcessTrustedWithOptions return false and I see the warning message appearing. When putting Xcode in the trusted apps, nothing changes. However, if I archive the app, I can run the archived .app and put the application into the trusted apps and AXIsProcessTrustedWithOptions returns true.

So. how can I get the permission granted from Xcode?

来源:https://stackoverflow.com/questions/58675555/how-to-grant-accessibilty-access-in-xcode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!