Code Monkey home page Code Monkey logo

beetee's Introduction

Swift Build Status codebeat badge DUB codecov

BeeTee

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.

Table of Contents

Limitations

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.

Installation

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

Usage

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

API

BeeTee

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:

Layer architecture of BeeTee

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.

Available Notifications

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 youself 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()

Known Issues

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. :-)

Contributions

Help is welcome! If you do not know what to do, just pick one item and send me a pull request.

  • Fix issue with multiple notifications
  • Provide a more detailed introduction to BeeTee installation if needed
  • Restructure BeeTee in a framework (BeeTee.framework, see discussion on stackoverflow)
  • Write test cases
  • Support Cocoapods
  • Improve documentation, especially inline documentation
  • Provide app icons
  • Support Travis support

Versions

3.0

  • Rewritten in Swift 3
  • New API
  • Clear separation of Objective-C and Swift code
  • Dynamically loading of Bluetooth.framework (so no more header and import trouble)
  • Released now under MIT license

3.0-beta

  • Rewritten in Swift 3
  • New API
  • Clear separation of Objective-C and Swift code
  • Dynamically loading of Bluetooth.framework (so no more header and import trouble)
  • Released now under MIT license

2.0

  • Wrapper classes MDBluetoothManager and MDBluetoothDevice introduced
  • Updated to ARC
  • Extented GUI

1.0

  • Initial Commit as demo project for BluetoothManager.framework, Non-ARC

License

BeeTee is released under the MIT license. See LICENSE for more details. The list icon was created by Aya Sofya (thenounproject.com).

beetee's People

Contributors

michaeldorner avatar

Watchers

Michael Scofield avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.