有没有办法在 iOS 中以编程方式打开和关闭蓝牙和/或 WiFi?
我正在寻找一种简单的方法来在 iOS 4.x 设备(iPhone 和 iPad)上切换蓝牙和 WiFi 的打开和关闭状态。
当我在不同的位置和使用场景之间移动时,我会不断地切换这些功能,现在需要多次点击并访问“设置”应用程序。我希望创建一个简单的应用程序,它位于 Springboard 上,我只需点击它,它就会关闭 wifi(如果它已打开),反之亦然,然后立即退出。与用于切换蓝牙状态的应用程序类似。
我拥有开发人员 SDK,并且熟悉 Xcode 和 iOS 开发,因此很乐意编写创建应用程序所需的代码。我只是不知道哪个 API(无论是否私有)具有简单切换这些设施状态所需的功能。
因为这是一个非常个人化的问题,我无意尝试销售该应用程序或将其放在应用程序商店中,因此遵守有关 API 使用的应用程序指南不是问题。我不想做的是越狱设备,因为我想保留核心软件。
任何人都可以向我指出一些示例代码或有关实现此目标的更多信息,因为我的 Google-fu 让我失望,如果有 4.x 设备的信息,我就是找不到它。
I am looking for an easy way to toggle both bluetooth and wifi between on and off states on iOS 4.x devices (iPhone and iPad).
I am constantly toggling these functions as I move between different locations and usage scenarios, and right now it takes multiple taps and visits to the Settings App. I am looking to create a simple App, that lives on Springboard, that I can just tap and it will turn off the wifi if it's on, and vice versa, then immediately quit. Similarly with an App for toggling bluetooth’s state.
I have the developer SDK, and am comfortable in Xcode and with iOS development, so am happy to write the required code to create the App. I am just at a loss as to which API, private or not, has the required functionality to simply toggle the state of these facilities.
Because this is scratching a very personal itch, I have no intent to try and sell the App or get it up on the App store, so conforming with App guidelines on API usage is a non-issue. What I don’t want to do is jailbreak the devices, as I want to keep the core software as shipped.
Can anyone point me at some sample code or more info on achieving this goal, as my Google-fu is letting me down, and if the information is out there for 4.x devices I just can’t find it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
感谢 Matt Farrugia(Twitter 上的@mattfarrugia),我一直在寻找的答案是:
您还需要链接到 Gamekit 框架,但只需将此代码添加到新的 Xcode 项目并在设备上运行即可。这样做会创建一个一键式应用程序,用于打开和关闭蓝牙。
Thanks to Matt Farrugia (@mattfarrugia on Twitter) the answer I was looking for was:
You need to link against the Gamekit framework as well, but simply add in this code to a new Xcode project and run on the device. Doing so creates a 1-tap App that toggles Bluetooth on and off.