问题
I want to try out the BluetoothManager. But I am really confused after reading and testing all the entries here.
First, I found in
Xcode/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk/System/Library/PrivateFrameworks/BluetoothManager.framework
the needed Framework. But there was only the binarie file there. So I add a "Headers" folder and put the BluetoothManager.h file in it.
In my project, I add this framework, but it couldn't find any BluetoothManager.h file, so I get an error, if I use
#import "BluetoothManager.h"
or
#import <BluetoothManager/BluetoothManager.h>
I want to use the following code to start 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 ;
}
I had tried also all the ideas here:
here or here or here
Has any one a realy good idea, a tutorial or a really running example for using (PrivateFramework/)BluetoothManager to toggle Bluetooth on iPhone, SKD 5.1?
Thank you very much.
isicom
回答1:
You can generate the header files using class-dump tools from github
Or copy/paste the below content(I generated for IOS 5.1) into BluetoothManager.h and add that file in your project. Then you should not see the error.
@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
回答2:
Here is a tutorial I wrote: http://www.pocketmagic.net/?p=2827 .
It shows how to configure Xcode with the BluetoothManager framework, then how to use these private apis to turn on/off bluetooth, discover nearby devices or connect to a remote bluetooth device. Tested with iOS 5.1
Let me know if there is anything else I can help you with.
来源:https://stackoverflow.com/questions/10272349/ios-5-1-toggle-bluetooth-by-bluetoothmanager