检查蓝牙是否已启用?
我只想简单检查设备上是否启用了蓝牙。
我不想从应用程序内部(或根本)更改状态、使用私有 API、越狱设备或执行任何会导致 Apple 拒绝应用程序的操作。
我只想知道蓝牙是否打开。
任何人都可以阐明这一点吗?有苹果允许的方法吗?
在阅读了无数的帖子和文档后,我完全意识到苹果在蓝牙(以及其他方面)方面非常严格。
如果您只能通过文档链接和/或一些关于学习 Objective-C、阅读文档等的讽刺评论来回答这个问题,那么请不要回复。
I just want to do a simple check of whether bluetooth is enabled on the device or not.
I don't want to change the status from inside an app (or at all), use private API's, jailbreak a device, or do anything that would cause Apple to reject an app.
All I want is to know whether bluetooth is turned on or not.
Can anyone shed any light on this? Is there any Apple-allowed way to do this?
I am fully aware, after reading countless posts and documentation that Apple is very restrictive when it comes to Bluetooth (among other things).
If you are only able to contribute to this question with a link to documentation and/or some snide remark about learning objective-c, reading documentation, etc., then please don't respond.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
现在,您可以使用 iOS 7 中的 CBCentralManager 进行检查,并使用 CBCentralManagerOptionShowPowerAlertKey 选项集对其进行初始化。
CBCentralManagerOptionShowPowerAlertKey 键,可以传递给 CBCentralManager 上的
initWithDelegate:queue:options:
方法,这将导致 iOS 启动 Central Manager &不提示用户启用蓝牙。发布于此处:http://chrismaddern.com/define-是否在 ios 上被动启用蓝牙/
You can now check this using the CBCentralManager in iOS 7 and initialize it with the CBCentralManagerOptionShowPowerAlertKey option set.
The CBCentralManagerOptionShowPowerAlertKey key, which can be passed to the
initWithDelegate:queue:options:
method on CBCentralManager which will cause iOS to start the Central Manager & not prompt the user to enable bluetooth.Posted here: http://chrismaddern.com/determine-whether-bluetooth-is-enabled-on-ios-passively/
我发现做到这一点的唯一方法是使用私有框架(例如蓝牙管理器),它仅对越狱应用程序有用......并且Apple将拒绝任何使用私有框架的应用程序。我相信使用蓝牙做任何事情都违反了他们的服务条款,所以你运气不好。
The only way I've ever found to do this is with private frameworks (like Bluetooth Manager, for one) that are only useful for Jailbroken apps... and Apple will reject any app using a private framework. I believe it's even against their ToS to do anything with bluetooth, so you're out of luck there.
这里似乎有一个答案 - 使用核心蓝牙框架
但是,该答案只会适用于 iOS 5.0 及更高版本。我自己还没有对此进行测试,但如果我发现它有效,我会返回并添加反馈。
There seems to be an answer here - Using Core bluetooth framework
However, that answer will only work for iOS 5.0 and up. I haven't tested this myself, but will return and add feedback if I find that it works.
不幸的是,SDK 不公开蓝牙方法。
可能有一种方法可以通过使用未记录的方法来做到这一点,但是我们都知道那里的问题。
Unfortunately not, the SDK does not expose Bluetooth methods.
There may be a way to do it by using undocumented methods, however we all know the problem there.
对于 iOS9+,您可以在此处查看我的答案。
For iOS9+, you can check my answer here.