Skip to content

Commit

Permalink
Added method for querying for sets of previously scanned peripherals
Browse files Browse the repository at this point in the history
  • Loading branch information
barelyreal committed Aug 16, 2016
1 parent 221b621 commit 169d8a6
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions Source/BKCentral.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 169d8a6

Please sign in to comment.