forked from rhummelmose/BluetoothKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c455d38
commit a8352d5
Showing
19 changed files
with
1,676 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
BluetoothKit.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>en</string> | ||
<key>CFBundleExecutable</key> | ||
<string>$(EXECUTABLE_NAME)</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>$(PRODUCT_NAME)</string> | ||
<key>CFBundlePackageType</key> | ||
<string>FMWK</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>1.0</string> | ||
<key>CFBundleSignature</key> | ||
<string>????</string> | ||
<key>CFBundleVersion</key> | ||
<string>$(CURRENT_PROJECT_VERSION)</string> | ||
<key>NSPrincipalClass</key> | ||
<string></string> | ||
</dict> | ||
</plist> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// | ||
// BKAvailability.swift | ||
// BluetoothKit | ||
// | ||
// Created by Rasmus Taulborg Hummelmose on 25/08/15. | ||
// Copyright © 2015 Wallmob A/S. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import CoreBluetooth | ||
|
||
public enum BKAvailability { | ||
|
||
case Available | ||
case Unavailable(cause: BKUnavailabilityCause) | ||
|
||
internal init(centralManagerState: CBCentralManagerState) { | ||
switch centralManagerState { | ||
case .PoweredOn: self = .Available | ||
default: self = .Unavailable(cause: BKUnavailabilityCause(centralManagerState: centralManagerState)) | ||
} | ||
} | ||
|
||
internal init(peripheralManagerState: CBPeripheralManagerState) { | ||
switch peripheralManagerState { | ||
case .PoweredOn: self = .Available | ||
default: self = .Unavailable(cause: BKUnavailabilityCause(peripheralManagerState: peripheralManagerState)) | ||
} | ||
} | ||
|
||
} | ||
|
||
public enum BKUnavailabilityCause: NilLiteralConvertible { | ||
|
||
case Any | ||
case Resetting | ||
case Unsupported | ||
case Unauthorized | ||
case PoweredOff | ||
|
||
public init(nilLiteral: Void) { | ||
self = Any | ||
} | ||
|
||
internal init(centralManagerState: CBCentralManagerState) { | ||
switch centralManagerState { | ||
case .PoweredOff: self = PoweredOff | ||
case .Resetting: self = Resetting | ||
case .Unauthorized: self = Unauthorized | ||
case .Unsupported: self = Unsupported | ||
default: self = nil | ||
} | ||
} | ||
|
||
internal init(peripheralManagerState: CBPeripheralManagerState) { | ||
switch peripheralManagerState { | ||
case .PoweredOff: self = PoweredOff | ||
case .Resetting: self = Resetting | ||
case .Unauthorized: self = Unauthorized | ||
case .Unsupported: self = Unsupported | ||
default: self = nil | ||
} | ||
} | ||
|
||
} | ||
|
||
public protocol BKAvailabilityDelegate: class { | ||
func availabilityObserver(availabilityObserver: AnyObject, availabilityDidChange availability: BKAvailability) | ||
func availabilityObserver(availabilityObserver: AnyObject, unavailabilityCauseDidChange unavailabilityCause: BKUnavailabilityCause) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// | ||
// BKCBCentralManagerDelegateProxy.swift | ||
// CustomerFacingDisplay | ||
// | ||
// Created by Rasmus Taulborg Hummelmose on 19/08/15. | ||
// Copyright © 2015 Wallmob A/S. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import CoreBluetooth | ||
|
||
internal protocol BKCBCentralManagerStateDelegate: class { | ||
func centralManagerDidUpdateState(central: CBCentralManager) | ||
} | ||
|
||
internal protocol BKCBCentralManagerDiscoveryDelegate: class { | ||
func centralManager(central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber) | ||
} | ||
|
||
internal protocol BKCBCentralManagerConnectionDelegate: class { | ||
func centralManager(central: CBCentralManager, didConnectPeripheral peripheral: CBPeripheral) | ||
func centralManager(central: CBCentralManager, didFailToConnectPeripheral peripheral: CBPeripheral, error: NSError?) | ||
func centralManager(central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: NSError?) | ||
} | ||
|
||
internal class BKCBCentralManagerDelegateProxy: NSObject, CBCentralManagerDelegate { | ||
|
||
// MARK: Public Implementation | ||
|
||
internal init(stateDelegate: BKCBCentralManagerStateDelegate, discoveryDelegate: BKCBCentralManagerDiscoveryDelegate, connectionDelegate: BKCBCentralManagerConnectionDelegate) { | ||
self.stateDelegate = stateDelegate | ||
self.discoveryDelegate = discoveryDelegate | ||
self.connectionDelegate = connectionDelegate | ||
super.init() | ||
} | ||
|
||
// MARK: Private Implementation | ||
|
||
internal weak var stateDelegate: BKCBCentralManagerStateDelegate? | ||
internal weak var discoveryDelegate: BKCBCentralManagerDiscoveryDelegate? | ||
internal weak var connectionDelegate: BKCBCentralManagerConnectionDelegate? | ||
|
||
internal func centralManagerDidUpdateState(central: CBCentralManager) { | ||
stateDelegate?.centralManagerDidUpdateState(central) | ||
} | ||
|
||
internal func centralManager(central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber) { | ||
discoveryDelegate?.centralManager(central, didDiscoverPeripheral: peripheral, advertisementData: advertisementData, RSSI: RSSI) | ||
} | ||
|
||
internal func centralManager(central: CBCentralManager, didConnectPeripheral peripheral: CBPeripheral) { | ||
connectionDelegate?.centralManager(central, didConnectPeripheral: peripheral) | ||
} | ||
|
||
internal func centralManager(central: CBCentralManager, didFailToConnectPeripheral peripheral: CBPeripheral, error: NSError?) { | ||
connectionDelegate?.centralManager(central, didFailToConnectPeripheral: peripheral, error: error) | ||
} | ||
|
||
internal func centralManager(central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: NSError?) { | ||
connectionDelegate?.centralManager(central, didDisconnectPeripheral: peripheral, error: error) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// | ||
// BKCBPeripheralDelegateProxy.swift | ||
// CustomerFacingDisplay | ||
// | ||
// Created by Rasmus Taulborg Hummelmose on 21/08/15. | ||
// Copyright © 2015 Wallmob A/S. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import CoreBluetooth | ||
|
||
internal protocol BKCBPeripheralDelegate: class { | ||
func peripheralDidUpdateName(peripheral: CBPeripheral) | ||
func peripheral(peripheral: CBPeripheral, didDiscoverServices error: NSError?) | ||
func peripheral(peripheral: CBPeripheral, didDiscoverCharacteristicsForService service: CBService, error: NSError?) | ||
func peripheral(peripheral: CBPeripheral, didUpdateValueForCharacteristic characteristic: CBCharacteristic, error: NSError?) | ||
} | ||
|
||
internal class BKCBPeripheralDelegateProxy: NSObject, CBPeripheralDelegate { | ||
|
||
// MARK: Internal | ||
|
||
internal weak var delegate: BKCBPeripheralDelegate? | ||
|
||
internal init(delegate: BKCBPeripheralDelegate) { | ||
self.delegate = delegate | ||
} | ||
|
||
// MARK: CBPeripheralDelegate | ||
|
||
internal func peripheralDidUpdateName(peripheral: CBPeripheral) { | ||
// print("peripheralDidUpdateName: \(peripheral)") | ||
delegate?.peripheralDidUpdateName(peripheral) | ||
} | ||
|
||
internal func peripheral(peripheral: CBPeripheral, didModifyServices invalidatedServices: [CBService]) { | ||
// print("peripheral: \(peripheral) didModifyServices invalidatedServices: \(invalidatedServices)") | ||
} | ||
|
||
internal func peripheralDidUpdateRSSI(peripheral: CBPeripheral, error: NSError?) { | ||
// print("peripheralDidUpdateRSSI: \(peripheral), error: \(error)") | ||
} | ||
|
||
internal func peripheral(peripheral: CBPeripheral, didReadRSSI RSSI: NSNumber, error: NSError?) { | ||
// print("peripheral: \(peripheral) didReadRSSI: \(RSSI), error: \(error)") | ||
} | ||
|
||
internal func peripheral(peripheral: CBPeripheral, didDiscoverServices error: NSError?) { | ||
// print("peripheral: \(peripheral) didDiscoverServices error: \(error)") | ||
delegate?.peripheral(peripheral, didDiscoverServices: error) | ||
} | ||
|
||
internal func peripheral(peripheral: CBPeripheral, didDiscoverIncludedServicesForService service: CBService, error: NSError?) { | ||
// print("peripheral: \(peripheral) didDiscoverIncludedServicesForService: \(service), error: \(error)") | ||
} | ||
|
||
internal func peripheral(peripheral: CBPeripheral, didDiscoverCharacteristicsForService service: CBService, error: NSError?) { | ||
// print("peripheral: \(peripheral) didDiscoverCharacteristicsForService: \(service), error: \(error)") | ||
delegate?.peripheral(peripheral, didDiscoverCharacteristicsForService: service, error: error) | ||
} | ||
|
||
internal func peripheral(peripheral: CBPeripheral, didUpdateValueForCharacteristic characteristic: CBCharacteristic, error: NSError?) { | ||
// print("peripheral: \(peripheral) didUpdateValueForCharacteristic: \(characteristic), error: \(error)") | ||
delegate?.peripheral(peripheral, didUpdateValueForCharacteristic: characteristic, error: error) | ||
} | ||
|
||
internal func peripheral(peripheral: CBPeripheral, didWriteValueForCharacteristic characteristic: CBCharacteristic, error: NSError?) { | ||
// print("peripheral: \(peripheral), didWriteValueForCharacteristic: \(characteristic), error: \(error)") | ||
} | ||
|
||
internal func peripheral(peripheral: CBPeripheral, didUpdateNotificationStateForCharacteristic characteristic: CBCharacteristic, error: NSError?) { | ||
// print("peripheral: \(peripheral) didUpdateNotificationStateForCharacteristic: \(characteristic), error: \(error)") | ||
} | ||
|
||
internal func peripheral(peripheral: CBPeripheral, didDiscoverDescriptorsForCharacteristic characteristic: CBCharacteristic, error: NSError?) { | ||
// print("peripheral: \(peripheral) didDiscoverDescriptorsForCharacteristic: \(characteristic), error: \(error)") | ||
} | ||
|
||
internal func peripheral(peripheral: CBPeripheral, didUpdateValueForDescriptor descriptor: CBDescriptor, error: NSError?) { | ||
// print("peripheral: \(peripheral) didUpdateValueForDescriptor: \(descriptor), error: \(error)") | ||
} | ||
|
||
internal func peripheral(peripheral: CBPeripheral, didWriteValueForDescriptor descriptor: CBDescriptor, error: NSError?) { | ||
// print("peripheral: \(peripheral) didWriteValueForDescriptor: \(descriptor), error: \(error)") | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// | ||
// BKCBPeripheralManagerDelegateProxy.swift | ||
// BluetoothKit | ||
// | ||
// Created by Rasmus Taulborg Hummelmose on 25/08/15. | ||
// Copyright © 2015 Wallmob A/S. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import CoreBluetooth | ||
|
||
internal protocol BKCBPeripheralManagerDelegate: class { | ||
func peripheralManagerDidUpdateState(peripheral: CBPeripheralManager) | ||
func peripheralManagerDidStartAdvertising(peripheral: CBPeripheralManager, error: NSError?) | ||
func peripheralManager(peripheral: CBPeripheralManager, didAddService service: CBService, error: NSError?) | ||
func peripheralManager(peripheral: CBPeripheralManager, central: CBCentral, didSubscribeToCharacteristic characteristic: CBCharacteristic) | ||
func peripheralManager(peripheral: CBPeripheralManager, central: CBCentral, didUnsubscribeFromCharacteristic characteristic: CBCharacteristic) | ||
func peripheralManagerIsReadyToUpdateSubscribers(peripheral: CBPeripheralManager) | ||
} | ||
|
||
internal class BKCBPeripheralManagerDelegateProxy: NSObject, CBPeripheralManagerDelegate { | ||
|
||
// MARK: Properties | ||
|
||
internal weak var delegate: BKCBPeripheralManagerDelegate? | ||
|
||
// MARK: Initializer | ||
|
||
internal init(delegate: BKCBPeripheralManagerDelegate) { | ||
self.delegate = delegate | ||
} | ||
|
||
// MARK: CBPeripheralManagerDelegate | ||
|
||
internal func peripheralManagerDidUpdateState(peripheral: CBPeripheralManager) { | ||
// print("peripheralManagerDidUpdateState: \(peripheral)") | ||
delegate?.peripheralManagerDidUpdateState(peripheral) | ||
} | ||
|
||
internal func peripheralManager(peripheral: CBPeripheralManager, willRestoreState dict: [String : AnyObject]) { | ||
// print("peripheralManager: \(peripheral) willRestoreState: \(dict)") | ||
} | ||
|
||
internal func peripheralManagerDidStartAdvertising(peripheral: CBPeripheralManager, error: NSError?) { | ||
// print("peripheralManagerDidStartAdvertising: \(peripheral) error: \(error)") | ||
delegate?.peripheralManagerDidStartAdvertising(peripheral, error: error) | ||
} | ||
|
||
internal func peripheralManager(peripheral: CBPeripheralManager, didAddService service: CBService, error: NSError?) { | ||
// print("peripheralManager: \(peripheral) didAddService: \(service) error: \(error)") | ||
delegate?.peripheralManager(peripheral, didAddService: service, error: error) | ||
} | ||
|
||
internal func peripheralManager(peripheral: CBPeripheralManager, central: CBCentral, didSubscribeToCharacteristic characteristic: CBCharacteristic) { | ||
// print("peripheralManager: \(peripheral) central: \(central) didSubscribeToCharacteristic: \(characteristic)") | ||
delegate?.peripheralManager(peripheral, central: central, didSubscribeToCharacteristic: characteristic) | ||
} | ||
|
||
internal func peripheralManager(peripheral: CBPeripheralManager, central: CBCentral, didUnsubscribeFromCharacteristic characteristic: CBCharacteristic) { | ||
// print("peripheralManager: \(peripheral) central: \(central) didUnsubscribeFromCharacteristic: \(characteristic)") | ||
delegate?.peripheralManager(peripheral, central: central, didUnsubscribeFromCharacteristic: characteristic) | ||
} | ||
|
||
internal func peripheralManager(peripheral: CBPeripheralManager, didReceiveReadRequest request: CBATTRequest) { | ||
// print("peripheralManager: \(peripheral) didReceiveReadRequest: \(request)") | ||
} | ||
|
||
internal func peripheralManager(peripheral: CBPeripheralManager, didReceiveWriteRequests requests: [CBATTRequest]) { | ||
// print("peripheralManager: \(peripheral) didReceiveWriteRequests: \(requests)") | ||
} | ||
|
||
internal func peripheralManagerIsReadyToUpdateSubscribers(peripheral: CBPeripheralManager) { | ||
// print("peripheralManagerIsReadyToUpdateSubscribers: \(peripheral)") | ||
delegate?.peripheralManagerIsReadyToUpdateSubscribers(peripheral) | ||
} | ||
|
||
} |
Oops, something went wrong.