diff --git a/Bluejay.podspec b/Bluejay.podspec
index 805dc2a..aa0e763 100644
--- a/Bluejay.podspec
+++ b/Bluejay.podspec
@@ -1,12 +1,12 @@
Pod::Spec.new do |spec|
spec.name = 'Bluejay'
- spec.version = '0.8.2'
+ spec.version = '0.8.3'
spec.license = { type: 'MIT', file: 'LICENSE' }
spec.homepage = 'https://github.com/steamclock/bluejay'
spec.authors = { 'Jeremy Chiang' => 'jeremy@steamclock.com' }
spec.summary = 'Bluejay is a simple Swift framework for building reliable Bluetooth apps.'
spec.homepage = 'https://github.com/steamclock/bluejay'
- spec.source = { git: 'https://github.com/steamclock/bluejay.git', tag: 'v0.8.2' }
+ spec.source = { git: 'https://github.com/steamclock/bluejay.git', tag: 'v0.8.3' }
spec.source_files = 'Bluejay/Bluejay/*.{h,swift}'
spec.framework = 'SystemConfiguration'
spec.platform = :ios, '10.0'
diff --git a/Bluejay/.jazzy.yaml b/Bluejay/.jazzy.yaml
index bbf0b4a..ab48a0f 100644
--- a/Bluejay/.jazzy.yaml
+++ b/Bluejay/.jazzy.yaml
@@ -2,7 +2,7 @@ output: ../docs
author: Steamclock Software
author_url: http://steamclock.com
module: Bluejay
-module_version: 0.8.2
+module_version: 0.8.3
readme: ../README.md
sdk: iphone
copyright: Copyright © 2017 Steamclock Software. All rights reserved.
diff --git a/Bluejay/Bluejay/Bluejay.swift b/Bluejay/Bluejay/Bluejay.swift
index 7607077..a6237c4 100644
--- a/Bluejay/Bluejay/Bluejay.swift
+++ b/Bluejay/Bluejay/Bluejay.swift
@@ -1402,7 +1402,9 @@ extension Bluejay: CBCentralManagerDelegate {
debugLog("Disconnect clean up: delivering expected disconnected event back to the pending connection in the queue...")
if let connection = weakSelf.queue.first as? Connection {
- if case let .stopping(error) = connection.state {
+ if case .running = connection.state {
+ connectingError = BluejayError.unexpectedDisconnect
+ } else if case let .stopping(error) = connection.state {
connectingError = error
}
}
diff --git a/Bluejay/Bluejay/Info.plist b/Bluejay/Bluejay/Info.plist
index a204eec..fd19e2c 100644
--- a/Bluejay/Bluejay/Info.plist
+++ b/Bluejay/Bluejay/Info.plist
@@ -15,7 +15,7 @@
CFBundlePackageType
FMWK
CFBundleShortVersionString
- 0.8.2
+ 0.8.3
CFBundleVersion
$(CURRENT_PROJECT_VERSION)
NSPrincipalClass
diff --git a/Bluejay/BluejayHeartSensorDemo/SensorViewController.swift b/Bluejay/BluejayHeartSensorDemo/SensorViewController.swift
index e0c16c8..22cf674 100644
--- a/Bluejay/BluejayHeartSensorDemo/SensorViewController.swift
+++ b/Bluejay/BluejayHeartSensorDemo/SensorViewController.swift
@@ -18,6 +18,10 @@ let chirpCharacteristic = CharacteristicIdentifier(
uuid: "83B4A431-A6F1-4540-B3EE-3C14AEF71A04",
service: ServiceIdentifier(uuid: "CED261B7-F120-41C8-9A92-A41DE69CF2A8")
)
+let pairingCharacteristic = CharacteristicIdentifier(
+ uuid: "E4D4A76C-B9F1-422F-8BBA-18508356A145",
+ service: ServiceIdentifier(uuid: "16274BFE-C539-416C-9646-CA3F991DADD6")
+)
class SensorViewController: UITableViewController {
@@ -55,7 +59,7 @@ class SensorViewController: UITableViewController {
if section == 0 {
return 3
} else {
- return 7
+ return 8
}
}
@@ -104,6 +108,8 @@ class SensorViewController: UITableViewController {
cell.textLabel?.text = "Stop listening to Dittojay"
} else if indexPath.row == 6 {
cell.textLabel?.text = "Terminate app"
+ } else if indexPath.row == 7 {
+ cell.textLabel?.text = "Pair"
}
return cell
@@ -138,6 +144,15 @@ class SensorViewController: UITableViewController {
endListen(to: chirpCharacteristic)
} else if indexPath.row == 6 {
kill(getpid(), SIGKILL)
+ } else if indexPath.row == 7 {
+ bluejay.read(from: pairingCharacteristic) { (result: ReadResult) in
+ switch result {
+ case .success(let data):
+ bluejay.log("Pairing success: \(String(data: data, encoding: .utf8) ?? "")")
+ case .failure(let error):
+ bluejay.log("Pairing failed with error: \(error.localizedDescription)")
+ }
+ }
}
tableView.deselectRow(at: indexPath, animated: true)
diff --git a/Bluejay/DittojayHeartSensorDemo/DittojayViewController.swift b/Bluejay/DittojayHeartSensorDemo/DittojayViewController.swift
index 9838715..de3b8dc 100644
--- a/Bluejay/DittojayHeartSensorDemo/DittojayViewController.swift
+++ b/Bluejay/DittojayHeartSensorDemo/DittojayViewController.swift
@@ -19,6 +19,9 @@ class DittojayViewController: UITableViewController {
var wakeAppCharacteristic: CBMutableCharacteristic!
var wakeAppService: CBMutableService!
+ var pairingCharacteristic: CBMutableCharacteristic!
+ var pairingService: CBMutableService!
+
var addedServices: [CBService] = []
var heartRate: UInt8 = 0
@@ -87,6 +90,31 @@ class DittojayViewController: UITableViewController {
advertiseServices([heartRateService.uuid])
}
+ private func addPairingService() {
+ let pairingServiceUUID = CBUUID(string: "16274BFE-C539-416C-9646-CA3F991DADD6")
+ let pairingCharacteristicUUID = CBUUID(string: "E4D4A76C-B9F1-422F-8BBA-18508356A145")
+
+ if addedServices.contains(where: { addedService -> Bool in
+ addedService.uuid == pairingServiceUUID
+ }) {
+ return
+ }
+
+ pairingCharacteristic = CBMutableCharacteristic(
+ type: pairingCharacteristicUUID,
+ properties: .read,
+ value: "Steamclock Software".data(using: .utf8),
+ permissions: .readEncryptionRequired
+ )
+
+ pairingService = CBMutableService(type: pairingServiceUUID, primary: true)
+ pairingService.characteristics = [pairingCharacteristic]
+
+ debugPrint("Will add pairing service...")
+
+ manager.add(pairingService)
+ }
+
private func advertiseServices(_ services: [CBUUID]) {
manager.startAdvertising([CBAdvertisementDataServiceUUIDsKey: services])
}
@@ -188,6 +216,7 @@ extension DittojayViewController: CBPeripheralManagerDelegate {
if peripheral.state == .poweredOn {
addHeartRateService()
addWakeAppService()
+ addPairingService()
}
}
@@ -234,4 +263,11 @@ extension DittojayViewController: CBPeripheralManagerDelegate {
func peripheralManager(_ peripheral: CBPeripheralManager, central: CBCentral, didUnsubscribeFrom characteristic: CBCharacteristic) {
debugPrint("Did unsubscribe from: \(characteristic.uuid.uuidString)")
}
+
+ func peripheralManager(_ peripheral: CBPeripheralManager, didReceiveRead request: CBATTRequest) {
+ debugPrint("Did receive read request for: \(request.characteristic.uuid.uuidString)")
+ if request.characteristic.uuid == pairingCharacteristic.uuid {
+ peripheral.respond(to: request, withResult: .success)
+ }
+ }
}