【问题标题】:Open the Bluetooth Settings Menu in Ios 10在 iOS 10 中打开蓝牙设置菜单
【发布时间】:2017-03-24 14:07:30
【问题描述】:

需要在IOS10及以上打开蓝牙设置菜单。但是[[UIApplication sharedApplication] openURL: [NSURL URLWithString:@"prefs:root=Bluetooth"]];在 ios 10 中不工作。

在浏览了多个文档后,我得到了下面的链接,该链接提供了可以正常工作的代码。 https://gist.github.com/johnny77221/bcaa5384a242b64bfd0b8a715f48e69f

但是,现在我有疑问应用商店会接受这个补丁代码,否则他们会拒绝申请。

请帮我解决这个问题。

提前致谢

【问题讨论】:

标签: objective-c ios10


【解决方案1】:

Swift 3.0:- 在 iOS 10.2 之前的所有 iOS 版本中工作

let url = URL(string: "App-Prefs:root") //用于系统设置app

@IBAction func blutootheButtonTapped(_ sender: AnyObject) {
let url = URL(string: "App-Prefs:root=Bluetooth") //for bluetooth setting 
    let app = UIApplication.shared
    app.openURL(url!)
}

【讨论】:

  • 当心,这被视为私有 API,Apple 拒绝了我的应用,因为我使用了 App-Prefs:root=Bluetooth。
【解决方案2】:

从 iOS 10 开始,应该使用“App-Prefs:root”而不是“prefs:root”。请参阅下面的目标 C 代码。对此进行了测试,代码运行良好,但 Apple 可能会因此拒绝该应用。

NSString *settingsUrl= @"App-Prefs:root=Bluetooth";
if ([[UIApplication sharedApplication] respondsToSelector:@selector(openURL:options:completionHandler:)]) {

        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:settingsUrl] options:@{} completionHandler:^(BOOL success) {
        NSLog(@"URL opened");
        }];
}

【讨论】:

    猜你喜欢
    • 2016-01-13
    • 1970-01-01
    • 1970-01-01
    • 2018-05-21
    • 2015-10-23
    • 1970-01-01
    • 2023-03-28
    • 2016-07-05
    • 2020-12-08
    相关资源
    最近更新 更多