Skip to content

Commit f38dab2

Browse files
committedMay 1, 2019
Refactoring.
Removed necessity to provide fixed MiaoMiao uuid. Thus the closest MiaoMiao will be connected.
1 parent 312da53 commit f38dab2

File tree

3 files changed

+21
-41
lines changed

3 files changed

+21
-41
lines changed
 

‎LibreMonitor.xcodeproj/project.pbxproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@
859859
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
860860
GCC_WARN_UNUSED_FUNCTION = YES;
861861
GCC_WARN_UNUSED_VARIABLE = YES;
862-
IPHONEOS_DEPLOYMENT_TARGET = 12.1;
862+
IPHONEOS_DEPLOYMENT_TARGET = 12.2;
863863
MAIN_APP_BUNDLE_IDENTIFIER = "$(inherited).LibreMonitorUI";
864864
MTL_ENABLE_DEBUG_INFO = YES;
865865
ONLY_ACTIVE_ARCH = YES;
@@ -920,7 +920,7 @@
920920
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
921921
GCC_WARN_UNUSED_FUNCTION = YES;
922922
GCC_WARN_UNUSED_VARIABLE = YES;
923-
IPHONEOS_DEPLOYMENT_TARGET = 12.1;
923+
IPHONEOS_DEPLOYMENT_TARGET = 12.2;
924924
MAIN_APP_BUNDLE_IDENTIFIER = "$(inherited).LibreMonitorUI";
925925
MTL_ENABLE_DEBUG_INFO = NO;
926926
SDKROOT = iphoneos;

‎LibreMonitor.xcworkspace/xcuserdata/Uwe.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

+14-14
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
ignoreCount = "0"
1111
continueAfterRunningActions = "Yes"
1212
filePath = "LibreMonitor/Model/Measurement.swift"
13-
timestampString = "565455383.823815"
13+
timestampString = "578429314.26016"
1414
startingColumnNumber = "9223372036854775807"
1515
endingColumnNumber = "9223372036854775807"
1616
startingLineNumber = "62"
@@ -34,11 +34,11 @@
3434
ignoreCount = "0"
3535
continueAfterRunningActions = "No"
3636
filePath = "LibreMonitor/Bluetooth/MiaoMiaoManager.swift"
37-
timestampString = "578129167.6082669"
37+
timestampString = "578429314.260875"
3838
startingColumnNumber = "9223372036854775807"
3939
endingColumnNumber = "9223372036854775807"
40-
startingLineNumber = "544"
41-
endingLineNumber = "544"
40+
startingLineNumber = "524"
41+
endingLineNumber = "524"
4242
landmarkName = "peripheral(_:didUpdateNotificationStateFor:error:)"
4343
landmarkType = "7">
4444
</BreakpointContent>
@@ -50,11 +50,11 @@
5050
ignoreCount = "0"
5151
continueAfterRunningActions = "No"
5252
filePath = "LibreMonitor/Bluetooth/MiaoMiaoManager.swift"
53-
timestampString = "578129167.609013"
53+
timestampString = "578429314.261102"
5454
startingColumnNumber = "9223372036854775807"
5555
endingColumnNumber = "9223372036854775807"
56-
startingLineNumber = "633"
57-
endingLineNumber = "633"
56+
startingLineNumber = "613"
57+
endingLineNumber = "613"
5858
landmarkName = "peripheral(_:didUpdateValueFor:error:)"
5959
landmarkType = "7">
6060
</BreakpointContent>
@@ -66,27 +66,27 @@
6666
ignoreCount = "0"
6767
continueAfterRunningActions = "No"
6868
filePath = "LibreMonitor/Bluetooth/MiaoMiaoManager.swift"
69-
timestampString = "578129167.609337"
69+
timestampString = "578429314.261165"
7070
startingColumnNumber = "9223372036854775807"
7171
endingColumnNumber = "9223372036854775807"
72-
startingLineNumber = "635"
73-
endingLineNumber = "635"
72+
startingLineNumber = "615"
73+
endingLineNumber = "615"
7474
landmarkName = "MiaoMiaoManager"
7575
landmarkType = "3">
7676
</BreakpointContent>
7777
</BreakpointProxy>
7878
<BreakpointProxy
7979
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
8080
<BreakpointContent
81-
shouldBeEnabled = "Yes"
81+
shouldBeEnabled = "No"
8282
ignoreCount = "0"
8383
continueAfterRunningActions = "No"
8484
filePath = "LibreMonitor/Bluetooth/MiaoMiaoManager.swift"
85-
timestampString = "578129167.609854"
85+
timestampString = "578429314.261223"
8686
startingColumnNumber = "9223372036854775807"
8787
endingColumnNumber = "9223372036854775807"
88-
startingLineNumber = "309"
89-
endingLineNumber = "309"
88+
startingLineNumber = "308"
89+
endingLineNumber = "308"
9090
landmarkName = "centralManager(_:willRestoreState:)"
9191
landmarkType = "7">
9292
</BreakpointContent>

‎LibreMonitor/Bluetooth/MiaoMiaoManager.swift

+5-25
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ final class MiaoMiaoManager: NSObject, CBCentralManagerDelegate, CBPeripheralDel
241241

242242
override init() {
243243
super.init()
244-
// centralManager = CBCentralManager(delegate: self, queue: nil, options: nil)
245244
centralManager = CBCentralManager(delegate: self, queue: nil, options: [CBCentralManagerOptionShowPowerAlertKey: true, CBCentralManagerOptionRestoreIdentifierKey: "LibreMonitorCoreBluetoothRestaurationKeyString"])
246245
}
247246

@@ -266,8 +265,8 @@ final class MiaoMiaoManager: NSObject, CBCentralManagerDelegate, CBPeripheralDel
266265
// First MiaoMiao: A44638E4-B70F-DBE7-A519-C4E4DFED2066
267266
// Second MiaoMiao: 3DE41921-6747-CDFD-D169-06EE86A81847
268267
os_log("Connect while state %{public}@", log: MiaoMiaoManager.bt_log, type: .default, String(describing: state.rawValue))
269-
// if let peripheral = peripheral {
270-
if let peripheral = peripheral, let identifier = UUID(uuidString: "3DE41921-6747-CDFD-D169-06EE86A81847"), peripheral.identifier == identifier {
268+
if let peripheral = peripheral {
269+
// if let peripheral = peripheral, let identifier = UUID(uuidString: "3DE41921-6747-CDFD-D169-06EE86A81847"), peripheral.identifier == identifier {
271270
peripheral.delegate = self
272271
centralManager.stopScan()
273272
centralManager.connect(peripheral, options: nil)
@@ -314,43 +313,24 @@ final class MiaoMiaoManager: NSObject, CBCentralManagerDelegate, CBPeripheralDel
314313
print(peripheral.description)
315314
if peripheral.state == .disconnecting || peripheral.state == .disconnected {
316315
self.peripheral = peripheral
316+
peripheral.delegate = self
317317
self.state = .Disconnected
318318
connect()
319319
} else {
320320
self.peripheral = peripheral
321321
peripheral.delegate = self
322322
self.state = .Connected
323323
peripheral.discoverServices(serviceUUIDs) // good practice to just discover the services, needed
324-
325-
// peripheral should already be connected
326324
}
327325
}
328326
} else {
329327
switch central.state {
330328
case .poweredOff, .resetting, .unauthorized, .unknown, .unsupported:
331329
state = .Unassigned
332-
case .poweredOn:
333-
scanForMiaoMiao() // power was switched on, while app is running -> reconnect.
330+
case .poweredOn: // Scanning will not work in background with MiaoMiao (since MiaoMiao does not advertise its services)
331+
scanForMiaoMiao() // power was switched on, while app is running
334332
}
335333
}
336-
// switch central.state {
337-
// case .poweredOff, .resetting, .unauthorized, .unsupported:
338-
// state = .Unassigned
339-
// case .poweredOn, .unknown:
340-
// if let peripheral = dict[CBCentralManagerRestoredStatePeripheralsKey] as? CBPeripheral {
341-
// self.peripheral = peripheral
342-
// // If the peripheral already exists:
343-
// // if disconnected, connect to it. Otherwhise it is already connected: disconnect and reconnect to get through the whole chain of methods.
344-
// if peripheral.state == .disconnected || peripheral.state == .disconnecting {
345-
// connect()
346-
// } else {
347-
// centralManager.cancelPeripheralConnection(peripheral)
348-
// connect()
349-
// }
350-
// } else {
351-
// scanForMiaoMiao()
352-
// }
353-
// }
354334
}
355335

356336

0 commit comments

Comments
 (0)
Please sign in to comment.