BeeTee
Demo application for Bluetooth device scanning using the iOS private framework "BluetoothManager"
Abstract
Because it is not trivial to use a private iOS framework, I implemented a demo application for the BluetoothManager.framework in ≥ iOS 7.
BeeTee offers two approaches, depending on what you want to try:
- An wrapper class called
MDBluetoothManager, where you can easily interact with the underlayingBluetoothManager.frameworkwithout any deeper knowledge aboutBluetoothManager.framework. - Because all of my implementation is open, you can study the underlaying
BluetoothManager.frameworkand how it works - but look out, it is not trivial.
Based on the AppStore guideline §2.5 not to use private (undocumented) functions it is not possible to publish apps with the BluetoothManager.framework in the AppStore. You may need a valid membership of the iOS Developer Program, because it makes sense that this app and framework does not work in the simulator.
Requirements for this app
- iOS 7 and greater
- iOS 7 compatible device (does not working on the simulator)
- Xcode 5 and greater
- Correctly placed header files (see Preparations)
Except the GUI the app and the framework as well works also fine for iOS 5 and 6. But take care about the path (see next paragraph).
Preparations
Just to clearify: Of course, since they are just two header files, it does not matter actually where the header files are placed in your project. But if you want to use the BluetoothManager.framework in other projects, it makes life easier just to import the framework with the headers.
- Find the folder, e.g. by terminal
open /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/System/Library/PrivateFrameworks/BluetoothManager.framework - Extract the Headers.zip archive and add the extracted folder
Headerswhich includesBluetoothManager.handBluetoothDevice.hin the directory above. - Restart Xcode
- Now you will find the
BluetoothManager.frameworkin Targets → YourApp → Build Phases → Link Binary With Libraries:
The folder can differ: Please take care about your iOS version!
For iOS 8 or later you can use a new bash script. This bash script checks if you have put your files correctly. just run it in the terminal with
bash path/to/the/bashscript/checkheaders.sh
Versions
2.0
- Wrapper classes
MDBluetoothManagerandMDBluetoothDeviceintroduced - Updated to ARC
- Extented GUI
1.0
- Initial Commit as demo project for
BluetoothManager.framework, Non-ARC
The MDBluetoothManager
Although all of my code is open source, I wrote a wrapper class which abstracts the BluetoothManager.framework for an easy handling.
The wrapper interface of this class is quite tiny:
@interface MDBluetoothManager : NSObject
+ (MDBluetoothManager *)sharedInstance;
- (BOOL)bluetoothIsAvailable; // is Bluetooth in general available?
// control Bluetooth
- (void)turnBluetoothOn;
- (BOOL)bluetoothIsPowered;
- (void)turnBluetoothOff;
// handling scans and its results
- (void)startScan;
- (BOOL)isScanning;
- (void)endScan;
- (NSArray*)discoveredBluetoothDevices;
// (un)register observers, which listen to MDBluetoothNotifications and implement the MDBluetoothObserverProtocol
- (void)registerObserver:(id<MDBluetoothObserverProtocol>)observer;
- (void)unregisterObserver:(id<MDBluetoothObserverProtocol>)observer;
@end
The protocol MDBluetoothObserverProtocol requires an implementation of the method
- (void)receivedBluetoothNotification:(MDBluetoothNotification)bluetoothNotification;
In that method you can handle the reaction to the Bluetooth notifications.
The BluetoothManager.framework
If you want to dive deeper into BluetoothManager.framework this section is interesting for you.
Available Notifications
BluetoothAvailabilityChangedNotification
BluetoothDiscoveryStateChangedNotification
BluetoothDeviceDiscoveredNotification
BluetoothDeviceRemovedNotification
// more methods they are not used in this app
BluetoothPowerChangedNotification
BluetoothConnectabilityChangedNotification
BluetoothDeviceUpdatedNotification
BluetoothDeviceConnectSuccessNotification
BluetoothConnectionStatusChangedNotification
BluetoothDeviceDisconnectSuccessNotification
Usage
Can be used e.g.
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(bluetoothAvailabilityChanged:) name:@"BluetoothAvailabilityChangedNotification" object:nil];
and
- (void)bluetoothAvailabilityChanged:(NSNotification *)notification { ... }
Troubleshooting
If you have problems make this project running have a look at Stackoverflow. If you have other questions or suggestions, feel free to contact me here in GitHub or somehow else. :-)
Licence
GPL (v3)
