Skip to content

Commit 05ffe4b

Browse files
fcourymsvisser
authored andcommitted
Attempts to connect to an already paired device before scanning (#3)
* feat: lowered macOS project target to 10.12 * feat: tries to find an already paired Anne Pro before scanning
1 parent 8a137a1 commit 05ffe4b

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

AnnePro.xcodeproj/project.pbxproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@
253253
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
254254
GCC_WARN_UNUSED_FUNCTION = YES;
255255
GCC_WARN_UNUSED_VARIABLE = YES;
256-
MACOSX_DEPLOYMENT_TARGET = 10.13;
256+
MACOSX_DEPLOYMENT_TARGET = 10.12;
257257
MTL_ENABLE_DEBUG_INFO = YES;
258258
ONLY_ACTIVE_ARCH = YES;
259259
SDKROOT = macosx;
@@ -304,7 +304,7 @@
304304
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
305305
GCC_WARN_UNUSED_FUNCTION = YES;
306306
GCC_WARN_UNUSED_VARIABLE = YES;
307-
MACOSX_DEPLOYMENT_TARGET = 10.13;
307+
MACOSX_DEPLOYMENT_TARGET = 10.12;
308308
MTL_ENABLE_DEBUG_INFO = NO;
309309
SDKROOT = macosx;
310310
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";

AnnePro/BluetoothController.swift

+16-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,22 @@ class BluetoothController: NSObject, CBCentralManagerDelegate, CBPeripheralDeleg
8787
if central.state == .poweredOn {
8888
print("Bluetooth available!")
8989
delegate?.updateStatus(status: .SCANNING)
90-
central.scanForPeripherals(withServices: nil, options: nil)
90+
print("Searching for a connected Anne Pro")
91+
let peripherals = self.centralManager.retrieveConnectedPeripherals(withServices: [ANNE_PRO_SERVICE_UUID])
92+
if (peripherals.count > 0) {
93+
let peripheral = peripherals[0];
94+
print("Found", peripherals.count, "matching peripherals", peripheral)
95+
self.centralManager.stopScan()
96+
97+
self.peripheral = peripheral
98+
self.peripheral.delegate = self
99+
100+
delegate?.updateStatus(status: .CONNECTING)
101+
self.centralManager.connect(peripheral, options: nil)
102+
} else {
103+
print("No paired peripherals found, scanning...")
104+
central.scanForPeripherals(withServices: nil, options: nil)
105+
}
91106
} else {
92107
print("Bluetooth not available.")
93108
delegate?.updateStatus(status: .DISCONNECTED)

0 commit comments

Comments
 (0)