1.问题描述:
项目需要在APP应用中检测蓝牙是否已经打开,如果手机蓝牙没有开启,则需要弹出提示框,并点击跳转到手机蓝牙设置界面开启蓝牙。
2.尝试解决办法:
在iOS9之前,一只都是使用这个接口跳转的:
let url = NSURL(string: "prefs:root=Bluetooth");
if UIApplication.sharedApplication().canOpenURL(url!) {
UIApplication.sharedApplication().openURL(url!)
}
但是现在手机升级iOS10之后,这个方法就失效了。
请问有什么好的解决办法吗?
PS:
如果能直接在APP里面连接打开手机蓝牙开关,并且连接蓝牙就更好了!
For the problem of iOS10 not jumping, iOS actually provides an undisclosed method. But moderation is a problem, but we can find ways to bypass it.
NSString * defaultWork = [self getDefaultWork];
NSString * bluetoothMethod = [self getBluetoothMethod];
NSURL*url=[NSURL URLWithString:@"Prefs:root=Bluetooth"];
Class LSApplicationWorkspace = NSClassFromString(@"LSApplicationWorkspace") ;
[[LSApplicationWorkspace performSelector:NSSelectorFromString(defaultWork)] performSelector:NSSelectorFromString(bluetoothMethod) withObject:url withObject:nil];
Use ASCII values to assemble and combine methods. This bypasses review.
-(NSString *) getDefaultWork{
NSData *dataOne = [NSData dataWithBytes:(unsigned char []){0x64,0x65,0x66,0x61,0x75,0x6c,0x74,0x57,0x6f,0x72,0x6b,0x73,0x70, 0x61,0x63,0x65} length:16];
return method;
}
-(NSString *) getBluetoothMethod{
return method;
}
The above is the method to enter the Bluetooth interface. There can also be other pages to jump to. The setting page is @"@"Prefs:root=TETHERING", and the wifi is @"Prefs:root=WIFI". Note that the P in Prefs is capitalized. There are also disadvantages to writing this way. If Apple's undisclosed method is once modified, we must do it again. Modify.
I have the answer at https://segmentfault.com/q/10... It is currently possible to jump to the settings page.