From 169d8a6a4aed1d185726b0ec8dfd7b7f957de085 Mon Sep 17 00:00:00 2001 From: Tyson Chihaya Date: Tue, 16 Aug 2016 13:49:38 +0200 Subject: [PATCH] Added method for querying for sets of previously scanned peripherals --- Source/BKCentral.swift | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/Source/BKCentral.swift b/Source/BKCentral.swift index 7877c83..f0c92a8 100644 --- a/Source/BKCentral.swift +++ b/Source/BKCentral.swift @@ -257,23 +257,43 @@ public class BKCentral: BKPeer, BKCBCentralManagerStateDelegate, BKConnectionPoo } } + /** + Retrieves a previously-scanned peripheral for direct connection. + - parameter remoteUUID: The UUID of the remote peripheral to look for + - return: optional remote peripheral if found + */ public func retrieveRemotePeripheralWithUUID (remoteUUID: NSUUID) -> BKRemotePeripheral? { - + guard let peripherals = retrieveRemotePeripheralsWithUUIDs([remoteUUID]) else { + return nil + } + guard peripherals.count > 0 else { + return nil + } + return peripherals[0] + } + + /** + Retrieves an array of previously-scanned peripherals for direct connection. + - parameter remoteUUIDs: An array of UUIDs of remote peripherals to look for + - return: optional array of found remote peripherals + */ + public func retrieveRemotePeripheralsWithUUIDs (remoteUUIDs: [NSUUID]) -> [BKRemotePeripheral]? { if let centralManager = _centralManager { - let peripherals = centralManager.retrievePeripheralsWithIdentifiers([remoteUUID]) + let peripherals = centralManager.retrievePeripheralsWithIdentifiers(remoteUUIDs) guard peripherals.count > 0 else { - // We have never scanned this peripheral before return nil } - let peripheral = BKRemotePeripheral(identifier: remoteUUID, peripheral: peripherals[0]) - peripheral.configuration = configuration - - return peripheral - } - else { - return nil + var remotePeripherals: [BKRemotePeripheral] = [] + + for peripheral in peripherals { + let remotePeripheral = BKRemotePeripheral(identifier: peripheral.identifier, peripheral: peripheral) + remotePeripheral.configuration = configuration + remotePeripherals.append(remotePeripheral) + } + return remotePeripherals } + return nil } // MARK: Internal Functions