Forked from devxoul/ios10-url-open-location-service.swift
Created
November 9, 2021 03:54
-
-
Save kingiol/477039c241b68cf0317ca411444d2b40 to your computer and use it in GitHub Desktop.
Open Settings > Privacy > Location Service in iOS 10
This file contains hidden or 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