我想试试蓝牙管理器。但在阅读并测试了这里的所有条目后,我感到非常困惑。
首先,我找到了
Xcode/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/System/Library/PrivateFrameworks/BluetoothManager.framework
所需的框架。但那里只有binarie文件。所以我添加了一个“Headers”文件夹并将BluetoothManager.h文件放入其中。
在我的项目中,我添加了这个框架,但它找不到任何BluetoothManager.h文件,所以我收到错误,如果我使用
#import "BluetoothManager.h"
或
#import <BluetoothManager/BluetoothManager.h>
我想使用以下代码启动BT:
- (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] ;
[btCont setPowered:YES] ;
#endif
return YES ;
}
我也试过这里的所有想法:
使用(PrivateFramework /)BluetoothManager在iPhone,SKD 5.1上切换蓝牙有任何一个真正的好主意,教程或真正运行的示例吗?
非常感谢。
isicom
答案 0 :(得分:3)
您可以使用github
中的类转储工具生成头文件或者将以下内容(我为IOS 5.1生成)复制/粘贴到BluetoothManager.h中,并在项目中添加该文件。那你就不应该看错了。
@class NSMutableDictionary;
@interface BluetoothManager : NSObject
{
struct BTLocalDeviceImpl *_localDevice;
struct BTSessionImpl *_session;
int _available;
BOOL _audioConnected;
BOOL _scanningEnabled;
BOOL _scanningInProgress;
unsigned int _scanningServiceMask;
struct BTDiscoveryAgentImpl *_discoveryAgent;
struct BTPairingAgentImpl *_pairingAgent;
struct BTAccessoryManagerImpl *_accessoryManager;
NSMutableDictionary *_btAddrDict;
NSMutableDictionary *_btDeviceDict;
}
+ (id)sharedInstance;
+ (int)lastInitError;
- (BOOL)available;
- (id)init;
- (BOOL)_attach:(id)arg1;
- (BOOL)_setup:(struct BTSessionImpl *)arg1;
- (void)_cleanup:(BOOL)arg1;
- (void)dealloc;
- (void)_postNotificationWithArray:(id)arg1;
- (void)_postNotification:(id)arg1;
- (void)postNotification:(id)arg1;
- (void)postNotificationName:(id)arg1 object:(id)arg2;
- (void)postNotificationName:(id)arg1 object:(id)arg2 error:(id)arg3;
- (int)powerState;
- (BOOL)powered;
- (BOOL)enabled;
- (BOOL)setPowered:(BOOL)arg1;
- (BOOL)setEnabled:(BOOL)arg1;
- (void)_powerChanged;
- (BOOL)isAnyoneScanning;
- (id)addDeviceIfNeeded:(struct BTDeviceImpl *)arg1;
- (void)_removeDevice:(id)arg1;
- (BOOL)wasDeviceDiscovered:(id)arg1;
- (BOOL)deviceScanningEnabled;
- (BOOL)deviceScanningInProgress;
- (void)resetDeviceScanning;
- (void)_scanForServices:(unsigned int)arg1 withMode:(int)arg2;
- (void)scanForServices:(unsigned int)arg1;
- (void)scanForConnectableDevices:(unsigned int)arg1;
- (void)setDeviceScanningEnabled:(BOOL)arg1;
- (void)_restartScan;
- (void)_setScanState:(int)arg1;
- (void)_discoveryStateChanged;
- (BOOL)isDiscoverable;
- (void)setDiscoverable:(BOOL)arg1;
- (BOOL)devicePairingEnabled;
- (void)setDevicePairingEnabled:(BOOL)arg1;
- (void)cancelPairing;
- (void)unpairDevice:(id)arg1;
- (id)pairedDevices:(BOOL)arg1;
- (id)pairedDevices;
- (id)pairedLEDevices;
- (void)setPincode:(id)arg1 forDevice:(id)arg2;
- (void)acceptSSP:(int)arg1 forDevice:(id)arg2;
- (void)connectDevice:(id)arg1 withServices:(unsigned int)arg2;
- (void)connectDevice:(id)arg1;
- (BOOL)connectable;
- (void)setConnectable:(BOOL)arg1;
- (id)connectingDevices;
- (id)connectedDevices;
- (BOOL)_onlySensorsConnected;
- (BOOL)connected;
- (void)_connectedStatusChanged;
- (void)_connectabilityChanged;
- (BOOL)audioConnected;
- (void)setAudioConnected:(BOOL)arg1;
- (void)startVoiceCommand:(id)arg1;
- (void)endVoiceCommand:(id)arg1;
- (BOOL)isServiceSupported:(unsigned int)arg1;
- (void)enableTestMode;
@end
答案 1 :(得分:1)
这是我写的教程:http://www.pocketmagic.net/?p=2827。
它展示了如何使用BluetoothManager框架配置Xcode,然后如何使用这些私有api打开/关闭蓝牙,发现附近的设备或连接到远程蓝牙设备。使用iOS 5.1进行测试
如果还有其他任何我可以帮助您,请告诉我。