点击按钮打开蓝牙设置
Open bluetooth settings on button tap
到目前为止,我已经做了足够多的查找,这在 iOS 5.1 及以下版本中是如何实现的,而在高于该版本的任何版本中都是不可能的。
但是其他应用是怎么做到的呢?
到目前为止,我已经尝试了以下方法(在 iOS 8.1 模拟器上测试,在 Xcode):
- (void)turnOnBlueToothPressed:(id)sender {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}
打开应用程序的设置。不理想,但就是这样。
据我所知,使用以下内容:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=General&path=Bluetooth"]]
不再有效。或者,谁能告诉我 官方文档说明它不再适用于任何版本 > iOS 5.1?
我也遇到了同样的问题,现在只能打开当前的应用设置,抱歉.....=(
https://developer.apple.com/library/ios/releasenotes/General/WhatsNewIniOS/Articles/iOS8.html
这适用于 iOS 版本 5.1 及更高版本 。
您必须在 Xcode 的 info.plist
选项卡中的 URL 类型 中添加 URL 方案 prefs
如下所示:
Objective-C:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=WIFI"]];
Swift:
UIApplication.sharedApplication().openURL(NSURL(string: "prefs:root=WIFI")!)
这将从您的应用程序打开 WIFI 设置。
相关 SO 链接:
- iOS Launching Settings -> Restrictions URL Scheme
- Call the official settings app from my app on iphone
注意:以下方法适用于 iOS11 以下的所有版本,对于更高版本,应用可能会被拒绝,因为它是私有的 API
这符合准则 2.5.1 - 性能 - 软件要求
这里是所有的列表:
如果你想打开蓝牙设置:
Swift 3 :
let url = URL(string: "App-Prefs:root=Bluetooth")
let app = UIApplication.shared
app.openURL(url!)
使用下面的代码打开设置:
UIApplication.sharedApplication().openURL(NSURL(string: UIApplicationOpenSettingsURLString))
到目前为止,我已经做了足够多的查找,这在 iOS 5.1 及以下版本中是如何实现的,而在高于该版本的任何版本中都是不可能的。
但是其他应用是怎么做到的呢?
到目前为止,我已经尝试了以下方法(在 iOS 8.1 模拟器上测试,在 Xcode):
- (void)turnOnBlueToothPressed:(id)sender {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}
打开应用程序的设置。不理想,但就是这样。
据我所知,使用以下内容:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=General&path=Bluetooth"]]
不再有效。或者,谁能告诉我 官方文档说明它不再适用于任何版本 > iOS 5.1?
我也遇到了同样的问题,现在只能打开当前的应用设置,抱歉.....=( https://developer.apple.com/library/ios/releasenotes/General/WhatsNewIniOS/Articles/iOS8.html
这适用于 iOS 版本 5.1 及更高版本 。
您必须在 Xcode 的 info.plist
选项卡中的 URL 类型 中添加 URL 方案 prefs
如下所示:
Objective-C:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=WIFI"]];
Swift:
UIApplication.sharedApplication().openURL(NSURL(string: "prefs:root=WIFI")!)
这将从您的应用程序打开 WIFI 设置。
相关 SO 链接:
- iOS Launching Settings -> Restrictions URL Scheme
- Call the official settings app from my app on iphone
注意:以下方法适用于 iOS11 以下的所有版本,对于更高版本,应用可能会被拒绝,因为它是私有的 API 这符合准则 2.5.1 - 性能 - 软件要求
这里是所有
如果你想打开蓝牙设置:
Swift 3 :
let url = URL(string: "App-Prefs:root=Bluetooth")
let app = UIApplication.shared
app.openURL(url!)
使用下面的代码打开设置:
UIApplication.sharedApplication().openURL(NSURL(string: UIApplicationOpenSettingsURLString))