Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions xDripG5.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@
CODE_SIGN_STYLE = Automatic;
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = ResetTransmitter/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.3;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.loopkit.ResetTransmitter;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -821,7 +821,7 @@
CODE_SIGN_STYLE = Automatic;
GCC_C_LANGUAGE_STANDARD = gnu11;
INFOPLIST_FILE = ResetTransmitter/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 11.3;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.loopkit.ResetTransmitter;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
27 changes: 9 additions & 18 deletions xDripG5/BluetoothManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class BluetoothManager: NSObject {

// MARK: - Actions

func scanForPeripheral(after delay: TimeInterval = 0) {
func scanForPeripheral() {
guard manager.state == .poweredOn else {
return
}
Expand All @@ -108,24 +108,19 @@ class BluetoothManager: NSObject {
return
}

var connectOptions: [String: Any] = [:]
if #available(iOS 11.2, watchOS 4.1, *), delay > 0 {
connectOptions[CBConnectPeripheralOptionStartDelayKey] = delay
}

if let peripheralID = self.peripheral?.identifier, let peripheral = manager.retrievePeripherals(withIdentifiers: [peripheralID]).first {
log.info("Re-connecting to known peripheral %{public}@ in %.1fs", peripheral.identifier.uuidString, delay)
log.debug("Re-connecting to known peripheral %{public}@", peripheral.identifier.uuidString)
self.peripheral = peripheral
self.manager.connect(peripheral, options: connectOptions)
self.manager.connect(peripheral)
} else if let peripheral = manager.retrieveConnectedPeripherals(withServices: [
TransmitterServiceUUID.advertisement.cbUUID,
TransmitterServiceUUID.cgmService.cbUUID
]).first, delegate == nil || delegate!.bluetoothManager(self, shouldConnectPeripheral: peripheral) {
log.info("Found system-connected peripheral: %{public}@", peripheral.identifier.uuidString)
log.debug("Found system-connected peripheral: %{public}@", peripheral.identifier.uuidString)
self.peripheral = peripheral
self.manager.connect(peripheral, options: connectOptions)
self.manager.connect(peripheral)
} else {
log.info("Scanning for peripherals")
log.debug("Scanning for peripherals")
manager.scanForPeripherals(withServices: [
TransmitterServiceUUID.advertisement.cbUUID
],
Expand Down Expand Up @@ -153,14 +148,10 @@ class BluetoothManager: NSObject {

*/
fileprivate func scanAfterDelay() {
if #available(iOS 11.2, watchOS 4.1, *) {
self.scanForPeripheral(after: TimeInterval(60 * 3))
} else {
DispatchQueue.global(qos: DispatchQoS.QoSClass.utility).async {
Thread.sleep(forTimeInterval: 2)
DispatchQueue.global(qos: DispatchQoS.QoSClass.utility).async {
Thread.sleep(forTimeInterval: 2)

self.scanForPeripheral()
}
self.scanForPeripheral()
}
}

Expand Down
2 changes: 1 addition & 1 deletion xDripG5/PeripheralManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ extension PeripheralManager {
func configureAndRun(_ block: @escaping (_ manager: PeripheralManager) -> Void) -> (() -> Void) {
return { [unowned self] in
if !self.needsConfiguration && self.peripheral.services == nil {
self.log.error("Configured peripheral has no services. Reconfiguring…")
self.log.debug("Configured peripheral has no services. Reconfiguring…")
}

if self.needsConfiguration || self.peripheral.services == nil {
Expand Down