Created
February 14, 2017 10:02
-
-
Save devxoul/49d7d8414bce22a7b629a16be9e7f8c0 to your computer and use it in GitHub Desktop.
Open Settings > Privacy > Location Service in iOS 10
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example Usage | |
func openLocation() { | |
guard let workspaceClass = NSClassFromString("LSApplicationWorkspace") else { return } | |
let workspace: AnyObject = execute(workspaceClass, "defaultWorkspace") | |
let url = URL(string: "Prefs:root=Privacy&path=LOCATION")! | |
execute(workspace, "openSensitiveURL:withOptions:", with: url) | |
} | |
private func getImplementation(_ owner: AnyObject, _ name: String) -> IMP { | |
let selector = Selector(name) | |
let method: Method | |
if let cls = owner as? AnyClass { | |
method = class_getClassMethod(cls, selector) | |
} else { | |
let cls: AnyClass = object_getClass(owner)! | |
method = class_getInstanceMethod(cls, selector) | |
} | |
return method_getImplementation(method) | |
} | |
func execute(_ owner: AnyObject, _ name: String, with arg1: Any? = nil, arg2: Any? = nil, arg3: Any? = nil) -> AnyObject { | |
let implementation = getImplementation(owner, name) | |
typealias Function = @convention(c) (AnyObject, Selector, Any?, Any?, Any?) -> Unmanaged<AnyObject> | |
let function = unsafeBitCast(implementation, to: Function.self) | |
return function(owner, Selector(name), arg1, arg2, arg3).takeRetainedValue() | |
} | |
func execute(_ owner: AnyObject, _ name: String, with arg1: Any? = nil, arg2: Any? = nil, arg3: Any? = nil) { | |
let implementation = getImplementation(owner, name) | |
typealias Function = @convention(c) (AnyObject, Selector, Any?, Any?, Any?) -> Void | |
let function = unsafeBitCast(implementation, to: Function.self) | |
return function(owner, Selector(name), arg1, arg2, arg3) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment