joh*_*hon 18 iphone bluetooth objective-c ipod-touch
我已经看到很多关于这个的问题,但实际上没有人给出真正的答案(导入框架,实际代码等).他们只说私人api,这将使你的应用程序从应用商店被拒绝.
我知道使用私人api会让我的应用被拒绝,我想知道如何将其用于个人用途.(iPhone SDK 3.1.2,iPod touch 2g)
mem*_*ons 10
我也一直在研究这个问题.您需要在项目中包含bluetoothmanager框架和头文件.它应该在
/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.0.sdk/System/Library/PrivateFrameworks/BluetoothManager.framework/
如果头文件不存在,则需要获取从库生成的.h文件并将其包含在项目中.我用谷歌搜索它; 这是一个在这里:
http://iphone-dev.googlecode.com/svn/branches/include-1.2-sdk/include/BluetoothManager/
一旦将其添加到项目中,如果头文件已在框架中,则导入应如下所示:
#import <BluetoothManager/BluetoothManager.h>
Run Code Online (Sandbox Code Playgroud)
或者,如果您将自己的BluetoothManager.h文件添加到项目中:
#import "BluetoothManager.h
Run Code Online (Sandbox Code Playgroud)
要在这里切换蓝牙是代码:
BluetoothManager *manager = [BluetoothManager sharedInstance];
[manager setEnabled:![manager enabled]];
Run Code Online (Sandbox Code Playgroud)
我已经构建了一个实用程序,我自己这样做,它确实有效.请注意,如果您只想创建一个实用程序来切换蓝牙并退出,而不使用任何UI,则在XCode中创建一个新项目并使用基于Window的应用程序模板.将代码添加到didFinishLaunchingWithOptions方法并替换[window makeKeyAndVisible]为exit(0).
您需要确保二进制文件和头文件在PrivateFrameworks文件夹中同时存在:
/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/System/Library/PrivateFrameworks
Run Code Online (Sandbox Code Playgroud)
这将允许您将BluetoothFrameworks(如BluetoothManager.framework)导入您的应用程序而不会出错.您可以在线找到如何获取标题.这适用于3.1.2 +因为我现在正在编写一个应用程序,它在我的设备和Sim上完美运行.
如果您要在模拟器中进行测试,请使用以下命令:
#if TARGET_IPHONE_SIMULATOR
//This is where simulator code goes that use private frameworks
#else
/* this works in iOS 4.2.1 */
Class BluetoothManager = objc_getClass("BluetoothManager");
id btCont = [BluetoothManager sharedInstance];
[btCont setPowered:YES];
#endif
Run Code Online (Sandbox Code Playgroud)
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
#if TARGET_IPHONE_SIMULATOR
exit( EXIT_SUCCESS ) ;
#else
/* this works in iOS 4.2.3 */
Class BluetoothManager = objc_getClass( "BluetoothManager" ) ;
id btCont = [BluetoothManager sharedInstance] ;
[self performSelector:@selector(toggle:) withObject:btCont afterDelay:1.0f] ;
#endif
return YES ;
}
#if TARGET_IPHONE_SIMULATOR
#else
- (void)toggle:(id)btCont
{
BOOL currentState = [btCont enabled] ;
[btCont setEnabled:!currentState] ;
[btCont setPowered:!currentState] ;
}
#endif
Run Code Online (Sandbox Code Playgroud)
上述方法适用于iOS 4.2.3
| 归档时间: |
|
| 查看次数: |
32993 次 |
| 最近记录: |