objective-c - iOS 有什么办法可以直接跳转到手机蓝牙设置界面连接蓝牙?
高洛峰
高洛峰 2017-04-18 09:48:47
0
1
705

1.问题描述:
项目需要在APP应用中检测蓝牙是否已经打开,如果手机蓝牙没有开启,则需要弹出提示框,并点击跳转到手机蓝牙设置界面开启蓝牙。

2.尝试解决办法:

在iOS9之前,一只都是使用这个接口跳转的:

 let url = NSURL(string: "prefs:root=Bluetooth");
 if UIApplication.sharedApplication().canOpenURL(url!) {
      UIApplication.sharedApplication().openURL(url!)
 }

但是现在手机升级iOS10之后,这个方法就失效了。
请问有什么好的解决办法吗?

PS:
如果能直接在APP里面连接打开手机蓝牙开关,并且连接蓝牙就更好了!

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(1)
黄舟

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];

NSString *method = [[NSString alloc] initWithData:dataOne encoding:NSASCIIStringEncoding];

return method;
}

-(NSString *) getBluetoothMethod{

NSData *dataOne = [NSData dataWithBytes:(unsigned char []){0x6f, 0x70, 0x65, 0x6e, 0x53, 0x65, 0x6e, 0x73, 0x69,0x74, 0x69,0x76,0x65,0x55,0x52,0x4c} length:16];
NSString *keyone = [[NSString alloc] initWithData:dataOne encoding:NSASCIIStringEncoding];
NSData *dataTwo = [NSData dataWithBytes:(unsigned char []){0x77,0x69,0x74,0x68,0x4f,0x70,0x74,0x69,0x6f,0x6e,0x73} length:11];
NSString *keytwo = [[NSString alloc] initWithData:dataTwo encoding:NSASCIIStringEncoding];
NSString *method = [NSString stringWithFormat:@"%@%@%@%@",keyone,@":",keytwo,@":"];

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!