在iphone sdk中以编程方式打开蓝牙? [英] Programmatically turn on bluetooth in the iphone sdk?

查看:38
本文介绍了在iphone sdk中以编程方式打开蓝牙?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到很多关于此的问题,但没有人真正给出真正的答案(导入的框架、实际代码等).他们只说带有私有 api,这会让您的应用被应用商店拒绝.

I have seen a lot of questions about this but no one actually gives a real answer (frameworks to import, actual code etc). They only say with a private api and that will get your app rejected from the app store.

我知道使用私有 api 会使我的应用程序被拒绝,因为我想知道如何将其用于个人用途.(iPhone SDK 3.1.2,iPod touch 2g)

I am aware that use of a private api will get my app rejected by I was wondering how to do it for personal use. (iPhone SDK 3.1.2, iPod touch 2g)

推荐答案

我也一直在研究这个问题.您需要在项目中包含 bluetoothmanager 框架和头文件.它应该

I've been looking into this as well. You need to include the bluetoothmanager framework and header file in your project. It should be in

/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/System/Library/PrivateFrameworks/BluetoothManager.framework/

如果头文件不存在,您需要获取从库生成的 .h 文件并将其包含在您的项目中.我用谷歌搜索找到它;这里有一个:

If the header file is not there, you'll need to grab a .h file that was generated from the library and include it in your project. I googled to find it; Here is one here:

http://iphone-dev.googlecode.com/svn/branches/include-1.2-sdk/include/BluetoothManager/

将其添加到您的项目后,如果头文件已在框架中,则您的导入应如下所示:

Once that is added to your project, your import should look like this if the header file was already in the framework:

#import <BluetoothManager/BluetoothManager.h>

或者,如果您将自己的 BluetoothManager.h 文件添加到您的项目中:

Or this if you added your own BluetoothManager.h file to your project:

#import "BluetoothManager.h

这里是切换蓝牙的代码:

To toggle the bluetooth here is the code:

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

我自己构建了一个实用程序来执行此操作,并且确实有效.请注意,如果您只想创建一个实用程序来切换蓝牙并退出,而无需任何 UI,请在 XCode 中创建一个新项目并使用基于窗口的应用程序模板.将代码添加到 didFinishLaunchingWithOptions 方法并将 [window makeKeyAndVisible] 替换为 exit(0).

I have built a utility to do this myself and it does work. Note, if all you want to do is create a utility to toggle the bluetooth and exit, without any UI, create a new project in XCode and use the Window-based Application template. Add the code to the didFinishLaunchingWithOptions method and replace [window makeKeyAndVisible] with exit(0).

这篇关于在iphone sdk中以编程方式打开蓝牙?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆