message shown when starting the scanning

This commit is contained in:
Johan Degraeve 2020-03-25 23:19:52 +01:00
parent 46bd3a8174
commit 3698775472
20 changed files with 90 additions and 41 deletions

View File

@ -165,7 +165,7 @@ class BluetoothTransmitter: NSObject, CBCentralManagerDelegate, CBPeripheralDele
trace("in startScanning", log: log, category: ConstantsLog.categoryBlueToothTransmitter, type: .info)
//assign default returnvalue
var returnValue = BluetoothTransmitter.startScanningResult.other(reason: "unknown")
var returnValue = BluetoothTransmitter.startScanningResult.success
// first check if already connected or connecting and if so stop processing
if let peripheral = peripheral {
@ -199,12 +199,21 @@ class BluetoothTransmitter: NSObject, CBCentralManagerDelegate, CBPeripheralDele
}
switch centralManager.state {
case .poweredOn:
trace(" starting bluetooth scanning", log: log, category: ConstantsLog.categoryBlueToothTransmitter, type: .info)
centralManager.scanForPeripherals(withServices: services, options: nil)
returnValue = .success
case .poweredOff:
trace(" bluetooth is not powered on", log: log, category: ConstantsLog.categoryBlueToothTransmitter, type: .error)
return .bluetoothNotPoweredOn(actualStateIs: "not powered on")
default:
trace(" bluetooth is not powered on, actual state is %{public}@", log: log, category: ConstantsLog.categoryBlueToothTransmitter, type: .info, "\(centralManager.state.toString())")
returnValue = .bluetoothNotPoweredOn(actualStateIs: centralManager.state.toString())
trace(" assumed started scanning, actual state is %{public}@", log: log, category: ConstantsLog.categoryBlueToothTransmitter, type: .info, returnValue.description())
return returnValue
}
} else {
trace(" centralManager is nil, can not starting scanning", log: log, category: ConstantsLog.categoryBlueToothTransmitter, type: .error)

View File

@ -121,5 +121,8 @@ enum ConstantsLog {
/// WatchManager logging
static let categoryWatchManager = "WatchManager "
/// bluetoothPeripheralViewController
static let bluetoothPeripheralViewController = "blePeripheralViewController "
}

View File

@ -315,7 +315,7 @@ extension BluetoothPeripheralManager: BluetoothTransmitterDelegate {
}
// create and schedule timer
PropertyHolder.transmitterPairingResponseTimer = Timer.scheduledTimer(timeInterval: 2, target: self, selector: #selector(informUserThatPairingTimedOut), userInfo: nil, repeats: false)
PropertyHolder.transmitterPairingResponseTimer = Timer.scheduledTimer(timeInterval: 60, target: self, selector: #selector(informUserThatPairingTimedOut), userInfo: nil, repeats: false)
}

View File

@ -453,7 +453,7 @@ class BluetoothPeripheralManager: NSObject {
/// - parameters:
/// - transmitterId : only for transmitter types that need it (at the moment only Dexcom and Blucon)
public func createNewTransmitter(type: BluetoothPeripheralType, transmitterId: String?) -> BluetoothTransmitter? {
public func createNewTransmitter(type: BluetoothPeripheralType, transmitterId: String?) -> BluetoothTransmitter {
switch type {
@ -468,8 +468,7 @@ class BluetoothPeripheralManager: NSObject {
case .DexcomG5Type:
guard let transmitterId = transmitterId, let cgmTransmitterDelegate = cgmTransmitterDelegate else {
trace("in createNewTransmitter, transmitterId is nil or cgmTransmitterDelegate is nil", log: log, category: ConstantsLog.categoryBluetoothPeripheralManager, type: .error)
return nil
fatalError("in createNewTransmitter, type DexcomG5Type, transmitterId is nil or cgmTransmitterDelegate is nil")
}
return CGMG5Transmitter(address: nil, name: nil, transmitterID: transmitterId, bluetoothTransmitterDelegate: self, cGMG5TransmitterDelegate: self, cGMTransmitterDelegate: cgmTransmitterDelegate)
@ -477,8 +476,7 @@ class BluetoothPeripheralManager: NSObject {
case .BubbleType:
guard let cgmTransmitterDelegate = cgmTransmitterDelegate else {
trace("in createNewTransmitter, cgmTransmitterDelegate is nil", log: log, category: ConstantsLog.categoryBluetoothPeripheralManager, type: .error)
return nil
fatalError("in createNewTransmitter, type DexcomG5Type, cgmTransmitterDelegate is nil")
}
return CGMBubbleTransmitter(address: nil, name: nil, bluetoothTransmitterDelegate: self, cGMBubbleTransmitterDelegate: self, cGMTransmitterDelegate: cgmTransmitterDelegate, timeStampLastBgReading: nil, sensorSerialNumber: nil, webOOPEnabled: nil, oopWebSite: nil, oopWebToken: nil)
@ -486,8 +484,7 @@ class BluetoothPeripheralManager: NSObject {
case .MiaoMiaoType:
guard let cgmTransmitterDelegate = cgmTransmitterDelegate else {
trace("in createNewTransmitter, cgmTransmitterDelegate is nil", log: log, category: ConstantsLog.categoryBluetoothPeripheralManager, type: .error)
return nil
fatalError("in createNewTransmitter, MiaoMiaoType, cgmTransmitterDelegate is nil")
}
return CGMMiaoMiaoTransmitter(address: nil, name: nil, bluetoothTransmitterDelegate: self, cGMMiaoMiaoTransmitterDelegate: self, cGMTransmitterDelegate: cgmTransmitterDelegate, timeStampLastBgReading: nil, sensorSerialNumber: nil, webOOPEnabled: nil, oopWebSite: nil, oopWebToken: nil)
@ -794,15 +791,17 @@ extension BluetoothPeripheralManager: BluetoothPeripheralManaging {
}
func startScanningForNewDevice(type: BluetoothPeripheralType, transmitterId: String?, callback: @escaping (BluetoothPeripheral) -> Void) {
func startScanningForNewDevice(type: BluetoothPeripheralType, transmitterId: String?, callback: @escaping (BluetoothPeripheral) -> Void) -> BluetoothTransmitter.startScanningResult {
callBackAfterDiscoveringDevice = callback
// create a temporary transmitter of requested type
tempBlueToothTransmitterWhileScanningForNewBluetoothPeripheral = createNewTransmitter(type: type, transmitterId: transmitterId)
let newBluetoothTranmsitter = createNewTransmitter(type: type, transmitterId: transmitterId)
tempBlueToothTransmitterWhileScanningForNewBluetoothPeripheral = newBluetoothTranmsitter
// start scanning
_ = tempBlueToothTransmitterWhileScanningForNewBluetoothPeripheral?.startScanning()
return newBluetoothTranmsitter.startScanning()
}

View File

@ -6,7 +6,7 @@ protocol BluetoothPeripheralManaging: BluetoothTransmitterDelegate {
/// to scan for a new BluetoothPeripheral - callback will be called when a new BluetoothPeripheral is found and connected
/// - parameters:
/// - transmitterId : only for devices that need a transmitterID (currently only Dexcom and Blucon)
func startScanningForNewDevice(type: BluetoothPeripheralType, transmitterId: String?, callback: @escaping (BluetoothPeripheral) -> Void)
func startScanningForNewDevice(type: BluetoothPeripheralType, transmitterId: String?, callback: @escaping (BluetoothPeripheral) -> Void) -> BluetoothTransmitter.startScanningResult
/// stops scanning for new device
func stopScanningForNewDevice()

View File

@ -18,3 +18,4 @@
"notTryingToConnect" = "Not trying to connect";
"disConnectedAt" = "Disconnected At";
"connectedAt" = "Connected At";
"startScanningInfo" = "Scannnig Started.\n\nKeep xDrip open on the foreground until a connection is made. (there's no need to turn off Auto-Lock. Just don't press the home button and don't lock the iOS device.)";

View File

@ -9,7 +9,6 @@
"startsensortimeinfo" = "In the next dialogs, you will need to set the date and time the sensor was inserted. It is important that you set the date and time as correct as possible. This is important for the accuracy.";
"scanbluetoothdeviceongoing" = "Busy scanning for transmitter";
"bluetoothisnoton" = "Bluetooth is not on. \r\n\r\nSwitch on Bluetooth first then try again.\r\n\r\nDo not connect to your device from your device settings. Scanning and connecting happens here in the app.";
"bluetoothdeviceconnectedinfo" = "Connected to Transmitter. Device details are stored. Future connection attempts will only use this transmitter.\r\n\r\nTo use another transmitter, select first 'Forget Transmitter'";
"sensorstart" = "Sensor Start";
"notstarted" = "not started";
"notknown" = "not known";

View File

@ -9,7 +9,6 @@
"startsensortimeinfo" = "In the next dialogs, you will need to set the date and time the sensor was inserted. It is important that you set the date and time as correct as possible. This is important for the accuracy.";
"scanbluetoothdeviceongoing" = "Busy scanning for transmitter";
"bluetoothisnoton" = "Bluetooth is not on. \r\n\r\nSwitch on Bluetooth first then try again.\r\n\r\nDo not connect to your device from your device settings. Scanning and connecting happens here in the app.";
"bluetoothdeviceconnectedinfo" = "Connected to Transmitter. Device details are stored. Future connection attempts will only use this transmitter.\r\n\r\nTo use another transmitter, select first 'Forget Transmitter'";
"sensorstart" = "Sensor Start";
"notstarted" = "not started";
"notknown" = "not known";

View File

@ -9,7 +9,6 @@
"startsensortimeinfo" = "In the next dialogs, you will need to set the date and time the sensor was inserted. It is important that you set the date and time as correct as possible. This is important for the accuracy.";
"scanbluetoothdeviceongoing" = "Busy scanning for transmitter";
"bluetoothisnoton" = "Bluetooth is not on. \r\n\r\nSwitch on Bluetooth first then try again.\r\n\r\nDo not connect to your device from your device settings. Scanning and connecting happens here in the app.";
"bluetoothdeviceconnectedinfo" = "Connected to Transmitter. Device details are stored. Future connection attempts will only use this transmitter.\r\n\r\nTo use another transmitter, select first 'Forget Transmitter'";
"sensorstart" = "Sensor Start";
"notstarted" = "not started";
"notknown" = "not known";

View File

@ -9,7 +9,6 @@
"startsensortimeinfo" = "In the next dialogs, you will need to set the date and time the sensor was inserted. It is important that you set the date and time as correct as possible. This is important for the accuracy.";
"scanbluetoothdeviceongoing" = "Busy scanning for transmitter";
"bluetoothisnoton" = "Bluetooth is not on. \r\n\r\nSwitch on Bluetooth first then try again.\r\n\r\nDo not connect to your device from your device settings. Scanning and connecting happens here in the app.";
"bluetoothdeviceconnectedinfo" = "Connected to Transmitter. Device details are stored. Future connection attempts will only use this transmitter.\r\n\r\nTo use another transmitter, select first 'Forget Transmitter'";
"sensorstart" = "Sensor Start";
"notstarted" = "not started";
"notknown" = "not known";

View File

@ -9,7 +9,6 @@
"startsensortimeinfo" = "In the next dialogs, you will need to set the date and time the sensor was inserted. It is important that you set the date and time as correct as possible. This is important for the accuracy.";
"scanbluetoothdeviceongoing" = "Busy scanning for transmitter";
"bluetoothisnoton" = "Bluetooth is not on. \r\n\r\nSwitch on Bluetooth first then try again.\r\n\r\nDo not connect to your device from your device settings. Scanning and connecting happens here in the app.";
"bluetoothdeviceconnectedinfo" = "Connected to Transmitter. Device details are stored. Future connection attempts will only use this transmitter.\r\n\r\nTo use another transmitter, select first 'Forget Transmitter'";
"sensorstart" = "Sensor Start";
"notstarted" = "not started";
"notknown" = "not known";

View File

@ -9,7 +9,6 @@
"startsensortimeinfo" = "In the next dialogs, you will need to set the date and time the sensor was inserted. It is important that you set the date and time as correct as possible. This is important for the accuracy.";
"scanbluetoothdeviceongoing" = "Busy scanning for transmitter";
"bluetoothisnoton" = "Bluetooth is not on. \r\n\r\nSwitch on Bluetooth first then try again.\r\n\r\nDo not connect to your device from your device settings. Scanning and connecting happens here in the app.";
"bluetoothdeviceconnectedinfo" = "Connected to Transmitter. Device details are stored. Future connection attempts will only use this transmitter.\r\n\r\nTo use another transmitter, select first 'Forget Transmitter'";
"sensorstart" = "Sensor Start";
"notstarted" = "not started";
"notknown" = "not known";

View File

@ -9,7 +9,6 @@
"startsensortimeinfo" = "In the next dialogs, you will need to set the date and time the sensor was inserted. It is important that you set the date and time as correct as possible. This is important for the accuracy.";
"scanbluetoothdeviceongoing" = "Busy scanning for transmitter";
"bluetoothisnoton" = "Bluetooth is not on. \r\n\r\nSwitch on Bluetooth first then try again.\r\n\r\nDo not connect to your device from your device settings. Scanning and connecting happens here in the app.";
"bluetoothdeviceconnectedinfo" = "Connected to Transmitter. Device details are stored. Future connection attempts will only use this transmitter.\r\n\r\nTo use another transmitter, select first 'Forget Transmitter'";
"sensorstart" = "Sensor Start";
"notstarted" = "niet gestart";
"notknown" = "not known";

View File

@ -9,7 +9,6 @@
"startsensortimeinfo" = "In the next dialogs, you will need to set the date and time the sensor was inserted. It is important that you set the date and time as correct as possible. This is important for the accuracy.";
"scanbluetoothdeviceongoing" = "Busy scanning for transmitter";
"bluetoothisnoton" = "Bluetooth is not on. \r\n\r\nSwitch on Bluetooth first then try again.\r\n\r\nDo not connect to your device from your device settings. Scanning and connecting happens here in the app.";
"bluetoothdeviceconnectedinfo" = "Connected to Transmitter. Device details are stored. Future connection attempts will only use this transmitter.\r\n\r\nTo use another transmitter, select first 'Forget Transmitter'";
"sensorstart" = "Sensor Start";
"notstarted" = "not started";
"notknown" = "not known";

View File

@ -9,7 +9,6 @@
"startsensortimeinfo" = "In the next dialogs, you will need to set the date and time the sensor was inserted. It is important that you set the date and time as correct as possible. This is important for the accuracy.";
"scanbluetoothdeviceongoing" = "Busy scanning for transmitter";
"bluetoothisnoton" = "Bluetooth is not on. \r\n\r\nSwitch on Bluetooth first then try again.\r\n\r\nDo not connect to your device from your device settings. Scanning and connecting happens here in the app.";
"bluetoothdeviceconnectedinfo" = "Connected to Transmitter. Device details are stored. Future connection attempts will only use this transmitter.\r\n\r\nTo use another transmitter, select first 'Forget Transmitter'";
"sensorstart" = "Sensor Start";
"notstarted" = "not started";
"notknown" = "not known";

View File

@ -9,7 +9,6 @@
"startsensortimeinfo" = "In the next dialogs, you will need to set the date and time the sensor was inserted. It is important that you set the date and time as correct as possible. This is important for the accuracy.";
"scanbluetoothdeviceongoing" = "Busy scanning for transmitter";
"bluetoothisnoton" = "Bluetooth is not on. \r\n\r\nSwitch on Bluetooth first then try again.\r\n\r\nDo not connect to your device from your device settings. Scanning and connecting happens here in the app.";
"bluetoothdeviceconnectedinfo" = "Connected to Transmitter. Device details are stored. Future connection attempts will only use this transmitter.\r\n\r\nTo use another transmitter, select first 'Forget Transmitter'";
"sensorstart" = "Sensor Start";
"notstarted" = "not started";
"notknown" = "not known";

View File

@ -9,7 +9,6 @@
"startsensortimeinfo" = "在下一个对话框中,您需要设置传感器插入的日期和时间. 输入正确的日期和时间是非常重要的. 尤其是对数据的准确度.";
"scanbluetoothdeviceongoing" = "正在扫描发射器";
"bluetoothisnoton" = "蓝牙未打开. 打开蓝牙并再次尝试.不要从设备的设置里直接配对. 扫描和配对都应该在app上进行.";
"bluetoothdeviceconnectedinfo" = "发射器已配对. 设备信息已保存. 再次配对会默认选择此发射器.要使用新的发射器,请先取消配对";
"sensorstart" = "启动探头";
"notstarted" = "未启动";
"notknown" = "未知";

View File

@ -19,7 +19,7 @@
<key>CFBundleShortVersionString</key>
<string>$(MARKETING_VERSION)</string>
<key>CFBundleVersion</key>
<string>3609</string>
<string>3619</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>

View File

@ -45,13 +45,13 @@ enum Texts_HomeView {
}()
static let bluetoothIsNotOn:String = {
return NSLocalizedString("bluetoothisnoton", tableName: filename, bundle: Bundle.main, value: "Bluetooth is not on. Switch on Bluetooth first then try again.", comment: "when user manually starts scanning but bluetooth is not on")
}()
static let bluetoothDeviceConnectedInfo:String = {
return NSLocalizedString("bluetoothdeviceconnectedinfo", tableName: filename, bundle: Bundle.main, value: "Connected to Transmitter. Device details are stored. Future connection attempts will only use this transmitter.\r\n\r\nTo use another transmitter, select first 'Forget Transmitter'", comment: "when user did manually start scanning, connection was successful")
return NSLocalizedString("bluetoothisnoton", tableName: filename, bundle: Bundle.main, value: "Bluetooth is not on. Switch on Bluetooth first then try again.", comment: "when user starts scanning but bluetooth is not on")
}()
static let startScanningInfo: String = {
return NSLocalizedString("startScanningInfo", tableName: filename, bundle: Bundle.main, value: "Scannnig Started.\n\nKeep xDrip open on the foreground until a connection is made. (there's no need to turn off Auto-Lock. Just don't press the home button and don't lock the iOS device.)", comment: "After clicking scan button, this message will appear")
}()
static let sensorStart:String = {
return NSLocalizedString("sensorstart", tableName: filename, bundle: Bundle.main, value: "Sensor Start", comment: "status info : literally 'Sensor Start'")
}()

View File

@ -1,5 +1,6 @@
import UIKit
import CoreBluetooth
import os
fileprivate let generalSettingSectionNumber = 0
@ -97,6 +98,12 @@ class BluetoothPeripheralViewController: UIViewController {
/// in which section do we find the weboop settings, if enabled
private let webOOPSettingsSectionNumber = 1
/// when user starts scanning, info will be shown in UIAlertController. This will be
private var infoAlertWhenScanningStarts: UIAlertController?
/// for trace
private let log = OSLog(subsystem: ConstantsLog.subSystem, category: ConstantsLog.bluetoothPeripheralViewController)
// MARK:- public functions
/// configure the viewController
@ -350,7 +357,7 @@ class BluetoothPeripheralViewController: UIViewController {
// if bluetoothPeripheralType needs transmitterId, then check that transmitterId is present
if type.needsTransmitterId() && transmitterIdTempValue == nil {return}
bluetoothPeripheralManager.startScanningForNewDevice(type: type, transmitterId: transmitterIdTempValue, callback: { (bluetoothPeripheral) in
let startScanningResult = bluetoothPeripheralManager.startScanningForNewDevice(type: type, transmitterId: transmitterIdTempValue, callback: { (bluetoothPeripheral) in
// set isScanning true
self.isScanning = false
@ -383,16 +390,51 @@ class BluetoothPeripheralViewController: UIViewController {
// reload the full screen , all rows in all sections in the tableView
self.tableView.reloadData()
// dismiss alert screen that shows info after cliking start scanning button
if let infoAlertWhenScanningStarts = self.infoAlertWhenScanningStarts {
infoAlertWhenScanningStarts.dismiss(animated: true, completion: nil)
self.infoAlertWhenScanningStarts = nil
}
})
// set isScanning true
isScanning = true
// check startScanningResult
switch startScanningResult {
case .success:
// disable the connect button
self.connectButtonOutlet.disable()
// app should be scanning now, update of cell is needed
tableView.reloadRows(at: [IndexPath(row: Setting.connectionStatus.rawValue, section: 0)], with: .none)
// set isScanning true
isScanning = true
// disable the connect button
self.connectButtonOutlet.disable()
// app should be scanning now, update of cell is needed
tableView.reloadRows(at: [IndexPath(row: Setting.connectionStatus.rawValue, section: 0)], with: .none)
self.infoAlertWhenScanningStarts = UIAlertController(title: Texts_HomeView.info, message: Texts_HomeView.startScanningInfo, actionHandler: nil)
self.present(self.infoAlertWhenScanningStarts!, animated:true)
case .alreadyScanning, .alreadyConnected, .connecting :
trace("in scanForBluetoothPeripheral, scanning not started. Scanning result = %{public}@", log: log, category: ConstantsLog.bluetoothPeripheralViewController, type: .error, startScanningResult.description())
// no further processing, should normally not happen,
case .bluetoothNotPoweredOn(let actualStateIs):
trace("in scanForBluetoothPeripheral, scanning not started. Bluetooth is not on, actual state = %{public}@", log: log, category: ConstantsLog.bluetoothPeripheralViewController, type: .error, actualStateIs)
self.infoAlertWhenScanningStarts = UIAlertController(title: Texts_Common.warning, message: Texts_HomeView.bluetoothIsNotOn, actionHandler: nil)
self.present(self.infoAlertWhenScanningStarts!, animated:true)
case .other(let reason):
trace("in scanForBluetoothPeripheral, scanning not started. Scanning result = %{public}@", log: log, category: ConstantsLog.bluetoothPeripheralViewController, type: .error, reason)
// no further processing, should normally not happen,
/*@unknown default:
trace("in scanForBluetoothPeripheral, scanning not started. Scanning result = %{public}@", log: log, category: ConstantsLog.bluetoothPeripheralViewController, type: .error, startScanningResult.description())
// no further processing, should normally not happen,*/
}
}
@ -426,7 +468,7 @@ class BluetoothPeripheralViewController: UIViewController {
}, cancelHandler: nil)
self.present(alert, animated:true)
}
/// user clicked connect button
@ -1015,6 +1057,12 @@ extension BluetoothPeripheralViewController: BluetoothTransmitterDelegate {
// refresh row with connection timestamp
tableView.reloadRows(at: [IndexPath(row: Setting.connectOrDisconnectTimeStamp.rawValue, section: 0)], with: .none)
// dismiss alert screen that shows info after cliking start scanning button
if let infoAlertWhenScanningStarts = infoAlertWhenScanningStarts {
infoAlertWhenScanningStarts.dismiss(animated: true, completion: nil)
self.infoAlertWhenScanningStarts = nil
}
}
func didDisconnectFrom(bluetoothTransmitter: BluetoothTransmitter) {