Demo application for Bluetooth device scanning using the iOS private framework "BluetoothManager"
BeeTee is an easy to use Swift framework, that allows simple access to the Bluetooth classic in iOS for turning on/off and scanning for Bluetooth devices.
Besides BeeTee demonstrates how to access the private BluetoothManager.framework
in iOS.
Based on the AppStore guideline §2.5 on private (undocumented) functions it is not possible to publish apps with the BeeTee and BluetoothManager.framework
in the AppStore.
You need a valid membership of the iOS Developer Program, because the BeeTee does not work in the iOS simulator.
Connecting to devices is not possible in most cases and, therefore, not yet supported.
There are currently no known limitations on iOS versions.
Copy all files in the BeeTee folder to your project and done. That means there are 9 files to copy:
BluetoothDevice.h
BluetoothManager.h
BluetoothDeviceHandler.h
BluetoothDeviceHandler.m
BluetoothManagerHandler.h
BluetoothManagerHandler.m
BeeTee-Bridge-Header.h
BeeTee.swift
BeeTeeDevice.swift
Here is a small code snippet, how easily you can use BeeTee:
class Demo: BeeTeeDelegate {
let beeTee = BeeTee()
init() {
beeTee.delegate = self
beeTee.enableBluetooth()
beeTee.startScanForDevices()
}
func receivedBeeTeeNotification(notification: BeeTeeNotification) {
switch notification {
case .DeviceDiscovered:
for device in beeTee.availableDevices {
print(device)
}
default:
print(notification)
}
}
}
The API is based on the other hardware managers, such as CLLocationManager
or the underlaying BluetoothManager.framework
.
I focused on a clear distinction between the different layers, also by using different programming languages:
BeeTeeNotification
public enum BeeTeeNotification {
case PowerChanged
case AvailabilityChanged
case DeviceDiscovered
case DeviceRemoved
case ConnectabilityChanged
case DeviceUpdated
case DiscoveryStateChanged
case DeviceConnectSuccess
case ConnectionStatusChanged
case DeviceDisconnectSuccess
static let allNotifications: [BeeTeeNotification]
}
So all known notification from BluetoothManager.framework
are passed through (see next section). I used only PowerChanged
, DeviceDiscovered
, DeviceRemoved
in my demo application.
BeeTeeDelegate
public protocol BeeTeeDelegate {
func receivedBeeTeeNotification(notification: BeeTeeNotification)
}
BeeTee
public class BeeTee {
public var delegate: BeeTeeDelegate?
public var availableDevices: [BeeTeeDevice]
convenience init(delegate: BeeTeeDelegate)
public func enableBluetooth()
public func disableBluetooth()
public func bluetoothIsEnabled() -> Bool
public func startScanForDevices()
public func stopScan()
public func isScanning() -> Bool
public static func debugLowLevel() // see section BluetoothManager.framework/Available Notification
}
BluetoothManager.framework
If you want to dive deeper into BluetoothManager.framework
this section is interesting for you.
I found the following notification regarding Bluetooth
BluetoothAvailabilityChangedNotification
BluetoothDiscoveryStateChangedNotification
BluetoothDeviceDiscoveredNotification
BluetoothDeviceRemovedNotification
BluetoothPowerChangedNotification
BluetoothConnectabilityChangedNotification
BluetoothDeviceUpdatedNotification
BluetoothDeviceConnectSuccessNotification
BluetoothConnectionStatusChangedNotification
BluetoothDeviceDisconnectSuccessNotification
Maybe the list is not complete. You can look for them yourself using
CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(),
nil,
{ (_, observer, name, _, _) in
let n = name?.rawValue as! String
if n.hasPrefix("B") { // notice only notification they are associated with the BluetoothManager.framework
print("Received notification: \(name)")
}
},
nil,
nil,
.deliverImmediately)
or with in BeeTee
:
BeeTee.debugLowLevel()
Actually I wanted to encapsulate BeeTee in a formal framework. But it seems that Swift does not allow framework-internal (protected) Objective-C code.
Some notifications are sent multiple times (issue). I am not sure how to deal with it.
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. 😃
Help is welcome! If you do not know what to do, just pick one item and send me a pull request.
BeeTee.framework
, see discussion on stackoverflow)Bluetooth.framework
(so no more header and import trouble)MDBluetoothManager
and MDBluetoothDevice
introducedBluetoothManager.framework
, Non-ARCBeeTee is released under the MIT license. See LICENSE for more details.
The list icon was created by Aya Sofya (thenounproject.com).