问题
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