2012-04-22 56 views
1

我想嘗試一下BluetoothManager。但在閱讀和測試這裏的所有條目後,我感到非常困惑。的iOS 5.1切換藍牙通過BluetoothManager

首先,我在

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 ; 
} 

我在這裏也試過所有的想法:

hereherehere

有任何一個真的好主意,一個教程或使用(PrivateFramework /)BluetoothManager切換藍牙在iPhone上,SKD 5.1一個真正運行的例子嗎?

非常感謝。

isicom

回答

3

可以使用類轉儲工具從GitHub

或複製生成的頭文件/粘貼到BluetoothManager.h(我的IOS 5.1生成)以下內容並添加該文件在您的項目。那麼你不應該看到錯誤。


@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 

+0

它也適用於iOS 6和全新的iOS 7公測!非常感謝你! – 2013-08-13 12:03:23

+0

我正在使用此代碼BOOL currentState = [btCont enabled]; [btCont setEnabled:!currentState];這顯示我錯誤,如多重方法命名setEnbled:在iOS 7 – 2014-01-24 07:19:42

+0

對於這些錯誤只需鍵入cast: [(BluetoothManager *)btCont setEnabled:!currentState]; – Yanchi 2014-02-08 14:20:21

1

這裏是一個教程中,我寫道:http://www.pocketmagic.net/?p=2827

它顯示瞭如何用BluetoothManager框架配置的Xcode,那麼如何使用這些私有的API來開啓/關閉藍牙,發現附近的設備或連接到遠程藍牙設備。與iOS 5.1

經測試讓我知道如果有什麼我可以幫你。

+0

我真的不能導入它,它說沒有找到,即使它是在圖書館,我可以看到「頭」文件夾中。 – Michal 2012-07-18 09:23:48

+0

嗨米哈爾,頭夾無關與框架本身,它是二進制。您需要爲#import子句添加標題,並在連接階段將BluetoothManager二進制文件作爲新項目框架添加到您的項目中。如果您無法添加框架,則應檢查BluetoothManager框架二進制文件是否位於您要導入的文件夾中。 – radhoo 2012-07-19 09:55:53

+0

是的,沒有得到它的工作,雖然nvm,我已經擦除它,現在我使用CoreBluetooth。 Thx的努力。 – Michal 2012-07-20 11:18:35