Skip to content

Instantly share code, notes, and snippets.

@mkll
Forked from johnny77221/openBLESetting
Created June 21, 2018 19:47
Show Gist options
  • Save mkll/44cbbb3a3a8b9218e5c34ede112f70f5 to your computer and use it in GitHub Desktop.
Save mkll/44cbbb3a3a8b9218e5c34ede112f70f5 to your computer and use it in GitHub Desktop.
opening iOS BLE setting from app
NSURL *bluetoothURLOS8 = [NSURL URLWithString:@"prefs:root=General&path=Bluetooth"];
NSURL *bluetoothURLOS9 = [NSURL URLWithString:@"prefs:root=Bluetooth"];
NSURL *bluetoothURLOS10 = [NSURL URLWithString:@"Prefs:root=Bluetooth"];
if ([[[UIDevice currentDevice] systemVersion] intValue] >= 10) {
Class<NSObject> workSpaceClass = NSClassFromString(@"LSApplicationWorkspace");
if (workSpaceClass) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
id workSpaceInstance = [workSpaceClass performSelector:NSSelectorFromString(@"defaultWorkspace")];
SEL selector = NSSelectorFromString(@"openSensitiveURL:withOptions:");
if ([workSpaceInstance respondsToSelector:selector]) {
[workSpaceInstance performSelector:selector withObject:bluetoothURLOS10 withObject:nil];
}
#pragma clang diagnostic pop
}
}
else if ([[[UIDevice currentDevice] systemVersion] intValue] >= 9) {
[[UIApplication sharedApplication] openURL:bluetoothURLOS9];
}
else {
[[UIApplication sharedApplication] openURL:bluetoothURLOS8];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment