简体   繁体   English

如何在ios9中按下按钮时打开蓝牙设置?

[英]How can I open bluetooth setting on button press in ios9?

I want to open bluetooth setting page on click of one button. 我想单击一个按钮打开蓝牙设置页面。 Currently, it is opening General page. 目前,它正在打开“常规”页面。

I am doing following for that: 为此,我正在做以下事情:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=Bluetooth"]];

Now you can open only current app settings, sorry ..... https://developer.apple.com/library/ios/releasenotes/General/WhatsNewIniOS/Articles/iOS8.html 现在,您只能打开当前的应用程序设置,对不起..... https://developer.apple.com/library/ios/releasenotes/General/WhatsNewIniOS/Articles/iOS8.html

You can on/off bluetooth by 您可以通过以下方式打开/关闭蓝牙

BluetoothManager *manager = [BluetoothManager sharedInstance];
[manager setEnabled:![manager enabled]];   

Use this URL Scheme: 使用以下URL方案:

prefs:root=General&path=Bluetooth prefs:root = General&path =蓝牙

Below is the code: 下面是代码:

NSURL*url=[[NSURL alloc] initWithString:@"prefs:root=General&path=Bluetooth"];
    if ([[UIApplication sharedApplication] canOpenURL:url]) {
        [[UIApplication sharedApplication] openURL:url];
    }

This will work for opening General screen in Settings for bluetooth 这适用于在“蓝牙设置”中打开“常规”屏幕

PS: Don't forget to add URL Types in targets info.plist file as shown below: PS:不要忘了在目标info.plist文件中添加URL Types ,如下所示:

网址类型

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在iOS中模拟按下主屏幕按钮? - How can I simulate a press of the home button in iOS? 在 iOS 4.3 中,当您按下主页按钮或按下开/关按钮时,我如何区分背景模式? - in iOS 4.3, how i can differentiate between the background mode, when you press the home button or when you press the on/off button? 如何在IOS中检查蓝牙是打开还是关闭? - How can i check the Bluetooth is ON or OFF in IOS? 如何使用代码模拟Swift iOS8中的按钮按下 - How can I simulate a button press in Swift iOS8 using code 如何在iOS的蓝牙键盘中检测何时按下播放按钮 - How can i detect when play button is pressed in a bluetooth keyboard in iOS 在蓝牙设备按钮按下时在后台录制音频 (iOS) - Record Audio in Background on Bluetooth Device Button Press (iOS) 如何在iOS9中从Safari打开URL方案? - How to open URL schemes from Safari in iOS9? 当我点击 MapKit 中的图钉时如何执行操作? ios9,快速 2 - How can I perform an action when I tap on a pin from MapKit? ios9, swift 2 如何在 iOS9 中更改 UIAlertController 按钮文本颜色? - How to change UIAlertController button text colour in iOS9? SWIFT iOS9:如何识别单击 UISearchBar 的 X 按钮 - SWIFT iOS9: How to recognize a click on the X button of the UISearchBar
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM