diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate
index 1a0ef08..aa45e5f 100644
--- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate
+++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate
Binary files differ
diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate
index 1a0ef08..aa45e5f 100644
--- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate
+++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate
Binary files differ
diff --git a/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift b/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift
index bddd67c..a61198f 100644
--- a/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift
+++ b/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift
@@ -34,7 +34,7 @@
@IBAction func toSearchLogView(_ sender: UIButton) {
// 弹框选择
let selectController = UIAlertController(title: "选择记录类型", message: nil, preferredStyle: .alert)
- let inspectButton = UIAlertAction(title: "巡检记录", style: .default, handler: { [self] _ in
+ let inspectButton = UIAlertAction(title: "巡检记录", style: .default, handler: { [self] _ in
navigationController?.pushViewController(InspectViewController(), animated: true)
})
let eventLogButton = UIAlertAction(title: "事件记录", style: .default, handler: { [self] _ in
diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate
index 1a0ef08..aa45e5f 100644
--- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate
+++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate
Binary files differ
diff --git a/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift b/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift
index bddd67c..a61198f 100644
--- a/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift
+++ b/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift
@@ -34,7 +34,7 @@
@IBAction func toSearchLogView(_ sender: UIButton) {
// 弹框选择
let selectController = UIAlertController(title: "选择记录类型", message: nil, preferredStyle: .alert)
- let inspectButton = UIAlertAction(title: "巡检记录", style: .default, handler: { [self] _ in
+ let inspectButton = UIAlertAction(title: "巡检记录", style: .default, handler: { [self] _ in
navigationController?.pushViewController(InspectViewController(), animated: true)
})
let eventLogButton = UIAlertAction(title: "事件记录", style: .default, handler: { [self] _ in
diff --git a/LaserMethane/ViewController/Map/MapViewController.swift b/LaserMethane/ViewController/Map/MapViewController.swift
index 12c4e01..60c3547 100644
--- a/LaserMethane/ViewController/Map/MapViewController.swift
+++ b/LaserMethane/ViewController/Map/MapViewController.swift
@@ -50,8 +50,9 @@
private var writeCharacteristic: CBCharacteristic!
private var deviceName: String!
private var cbPeripheral: CBPeripheral!
- //弹窗里面的输入框
+ // 弹窗里面的输入框
private var inputTextField: UITextField!
+ private var inspectionId: String!
override func viewDidLoad() {
super.viewDidLoad()
@@ -67,17 +68,19 @@
// 蓝牙相关
centralManager = CBCentralManager()
centralManager.delegate = self
- // 设置地图
- setUpMap()
- // 在地图图层上面View
- topTagView = UIView(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: 55))
- topTagView.backgroundColor = UIColor(red: 214 / 255, green: 238 / 255, blue: 254 / 255, alpha: 1.0)
- addTopTagSubview()
- addLeftSubview()
- addBottomSubview()
- view.addSubview(topTagView)
// 新建巡检弹窗
creatNewInspection()
+ // 延时加载地图
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [self] in
+ setUpMap()
+ // 在地图图层上面View
+ topTagView = UIView(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: 55))
+ topTagView.backgroundColor = UIColor(red: 214 / 255, green: 238 / 255, blue: 254 / 255, alpha: 1.0)
+ addTopTagSubview()
+ addLeftSubview()
+ addBottomSubview()
+ view.addSubview(topTagView)
+ }
}
func setUpMap() {
@@ -139,11 +142,12 @@
make.left.equalTo(5)
}
+ inspectTimeLabel.textAlignment = .right
topTagView.addSubview(inspectTimeLabel)
inspectTimeLabel.snp.makeConstraints { (make) -> Void in
make.size.equalTo(CGSize(width: topTagView.frame.width / 2, height: 20))
make.top.equalTo(30)
- make.right.equalTo(5)
+ make.right.equalTo(-5)
}
}
@@ -190,9 +194,9 @@
if isBluetoothAvailable() {
LoadingHub.shared.showLoading(text: "设备搜索中...")
centralManager.scanForPeripherals(withServices: nil, options: nil)
- DispatchQueue.main.asyncAfter(deadline: .now() + 3, execute: {
+ DispatchQueue.main.asyncAfter(deadline: .now() + 3, execute: { [self] in
// 列表显示扫描到的设备
- self.showTableView()
+ showTableView()
})
} else {
AlertHub.shared.showWaringAlert(controller: self, message: "蓝牙不可用,请检查")
@@ -203,25 +207,30 @@
centralManager.stopScan()
LoadingHub.shared.hideLoading()
- let actionSheetController = UIAlertController()
- for device in scanDevices {
- actionSheetController.addAction(UIAlertAction(title: device.name, style: .default, handler: { [self] alertAction in
- // 连接点击的设备
- LoadingHub.shared.showLoading(text: "设备连接中...")
- scanDevices.forEach { it in
- if alertAction.title == it.name {
- centralManager.connect(it, options: nil)
+ if scanDevices.count == 0 {
+ AlertHub.shared.showWaringAlert(controller: self, message: "无可用设备,请确认设备是否已开启")
+ } else {
+ let actionSheetController = UIAlertController()
+ for device in scanDevices {
+ actionSheetController.addAction(UIAlertAction(title: device.name, style: .default, handler: { [self] alertAction in
+ // 连接点击的设备
+ LoadingHub.shared.showLoading(text: "设备连接中...")
+ scanDevices.forEach { it in
+ if alertAction.title == it.name {
+ centralManager.connect(it, options: nil)
+ }
}
- }
- }))
+ }))
+ }
+ actionSheetController.addAction(UIAlertAction(title: "取消", style: .cancel))
+ present(actionSheetController, animated: true, completion: nil)
}
- actionSheetController.addAction(UIAlertAction(title: "取消", style: .cancel))
- present(actionSheetController, animated: true, completion: nil)
}
// 重新发送指令
@IBAction func refreshCmdAction(_ sender: Any) {
if isBluetoothAvailable() {
+ writeToPeripheral(OPEN_TRANSFER_COMMAND)
} else {
AlertHub.shared.showWaringAlert(controller: self, message: "请先连接设备")
}
@@ -232,7 +241,7 @@
view.addSubview(currentView)
currentView.snp.makeConstraints { (make) -> Void in
make.size.equalTo(CGSize(width: viewWidth, height: viewHeight))
- make.bottom.equalTo(-(SCREEN_HEIGHT * 0.1 + 10))
+ make.bottom.equalTo(-(SCREEN_HEIGHT * 0.1 + 20))
make.left.equalTo(10)
}
@@ -240,7 +249,7 @@
view.addSubview(settingView)
settingView.snp.makeConstraints { (make) -> Void in
make.size.equalTo(CGSize(width: viewWidth, height: viewHeight))
- make.bottom.equalTo(-(SCREEN_HEIGHT * 0.1 + 10))
+ make.bottom.equalTo(-(SCREEN_HEIGHT * 0.1 + 20))
make.centerX.equalToSuperview()
}
@@ -248,7 +257,7 @@
view.addSubview(maxView)
maxView.snp.makeConstraints { (make) -> Void in
make.size.equalTo(CGSize(width: viewWidth, height: viewHeight))
- make.bottom.equalTo(-(SCREEN_HEIGHT * 0.1 + 10))
+ make.bottom.equalTo(-(SCREEN_HEIGHT * 0.1 + 20))
make.right.equalTo(-10)
}
@@ -270,14 +279,29 @@
inputTextField = textField
inputTextField.delegate = self
}
- let actionOK = UIAlertAction(title: "保存", style: .default) { [self] (_: UIAlertAction) -> Void in
+ let actionOK = UIAlertAction(title: "开始巡检", style: .default) { [self] (_: UIAlertAction) -> Void in
if inputTextField.text == "" {
AlertHub.shared.showWaringAlert(controller: self, message: "巡检标签不能为空")
return
}
+ // 获取当前时间戳
+ let timeInterval: TimeInterval = Date().timeIntervalSince1970
+ let timeStamp = Int(timeInterval)
+ // 新建巡检,inspectionId必为空
+ inspectionId = timeStamp.id()
+ print("巡检id: \(inspectionId!)")
+ // 设置标题和时间
inspectNameLabel.text = inputTextField.text!
+ let dateformatter = DateFormatter()
+ dateformatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
+ inspectTimeLabel.text = dateformatter.string(from: Date(timeIntervalSince1970: timeInterval))
+
+ //开始巡检
+ startInspection()
}
- let actionCancel = UIAlertAction(title: "取消", style: .cancel, handler: nil)
+ let actionCancel = UIAlertAction(title: "放弃", style: .cancel) { [self] (_: UIAlertAction) -> Void in
+ navigationController?.popViewController(animated: true)
+ }
// 设置取消按钮颜色为红色
actionCancel.setValue(UIColor(red: 255 / 255, green: 0 / 255, blue: 0 / 255, alpha: 1), forKey: "titleTextColor")
msgAlertCtr.addAction(actionOK)
@@ -285,6 +309,10 @@
present(msgAlertCtr, animated: true, completion: nil)
}
+ func startInspection() {
+ //巡检主要就是记录巡检员的位置
+ }
+
@IBAction func addEventAction(_ sender: Any) {
let lng = keychain[Constant.CurrentLongitude.rawValue]! as String
let lat = keychain[Constant.CurrentLatitude.rawValue]! as String
@@ -294,15 +322,13 @@
// 委托代理
valueDelegate = newEventViewController
let selectController = UIAlertController(title: "选择事件类型", message: nil, preferredStyle: .alert)
- // 获取当前时间戳
- let timeInterval: TimeInterval = Date().timeIntervalSince1970
- let timeStamp = Int(timeInterval)
+
let inspectButton = UIAlertAction(title: "报警事件", style: .default, handler: { [self] _ in
// 实现代理的方法,传值
valueDelegate.transfer(controller: self,
dic: ["isWarning": true,
- "inspectionId": timeStamp.id(),
- "inspectionName": inspectNameLabel.text,
+ "inspectionId": inspectionId!,
+ "inspectionName": inspectNameLabel.text!,
"longitude": Double(lng)!,
"latitude": Double(lat)!])
navigationController?.pushViewController(newEventViewController, animated: true)
@@ -311,8 +337,8 @@
// 实现代理的方法,传值
valueDelegate.transfer(controller: self,
dic: ["isWarning": false,
- "inspectionId": timeStamp.id(),
- "inspectionName": inspectNameLabel.text,
+ "inspectionId": inspectionId!,
+ "inspectionName": inspectNameLabel.text!,
"longitude": Double(lng)!,
"latitude": Double(lat)!])
navigationController?.pushViewController(newEventViewController, animated: true)
@@ -509,7 +535,5 @@
}
}
-
extension MapViewController: UITextFieldDelegate {
-
}
diff --git a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate
index 1a0ef08..aa45e5f 100644
--- a/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate
+++ b/LaserMethane.xcworkspace/xcuserdata/a203.xcuserdatad/UserInterfaceState.xcuserstate
Binary files differ
diff --git a/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift b/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift
index bddd67c..a61198f 100644
--- a/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift
+++ b/LaserMethane/ViewController/MainMenu/MainMenuViewController.swift
@@ -34,7 +34,7 @@
@IBAction func toSearchLogView(_ sender: UIButton) {
// 弹框选择
let selectController = UIAlertController(title: "选择记录类型", message: nil, preferredStyle: .alert)
- let inspectButton = UIAlertAction(title: "巡检记录", style: .default, handler: { [self] _ in
+ let inspectButton = UIAlertAction(title: "巡检记录", style: .default, handler: { [self] _ in
navigationController?.pushViewController(InspectViewController(), animated: true)
})
let eventLogButton = UIAlertAction(title: "事件记录", style: .default, handler: { [self] _ in
diff --git a/LaserMethane/ViewController/Map/MapViewController.swift b/LaserMethane/ViewController/Map/MapViewController.swift
index 12c4e01..60c3547 100644
--- a/LaserMethane/ViewController/Map/MapViewController.swift
+++ b/LaserMethane/ViewController/Map/MapViewController.swift
@@ -50,8 +50,9 @@
private var writeCharacteristic: CBCharacteristic!
private var deviceName: String!
private var cbPeripheral: CBPeripheral!
- //弹窗里面的输入框
+ // 弹窗里面的输入框
private var inputTextField: UITextField!
+ private var inspectionId: String!
override func viewDidLoad() {
super.viewDidLoad()
@@ -67,17 +68,19 @@
// 蓝牙相关
centralManager = CBCentralManager()
centralManager.delegate = self
- // 设置地图
- setUpMap()
- // 在地图图层上面View
- topTagView = UIView(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: 55))
- topTagView.backgroundColor = UIColor(red: 214 / 255, green: 238 / 255, blue: 254 / 255, alpha: 1.0)
- addTopTagSubview()
- addLeftSubview()
- addBottomSubview()
- view.addSubview(topTagView)
// 新建巡检弹窗
creatNewInspection()
+ // 延时加载地图
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [self] in
+ setUpMap()
+ // 在地图图层上面View
+ topTagView = UIView(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: 55))
+ topTagView.backgroundColor = UIColor(red: 214 / 255, green: 238 / 255, blue: 254 / 255, alpha: 1.0)
+ addTopTagSubview()
+ addLeftSubview()
+ addBottomSubview()
+ view.addSubview(topTagView)
+ }
}
func setUpMap() {
@@ -139,11 +142,12 @@
make.left.equalTo(5)
}
+ inspectTimeLabel.textAlignment = .right
topTagView.addSubview(inspectTimeLabel)
inspectTimeLabel.snp.makeConstraints { (make) -> Void in
make.size.equalTo(CGSize(width: topTagView.frame.width / 2, height: 20))
make.top.equalTo(30)
- make.right.equalTo(5)
+ make.right.equalTo(-5)
}
}
@@ -190,9 +194,9 @@
if isBluetoothAvailable() {
LoadingHub.shared.showLoading(text: "设备搜索中...")
centralManager.scanForPeripherals(withServices: nil, options: nil)
- DispatchQueue.main.asyncAfter(deadline: .now() + 3, execute: {
+ DispatchQueue.main.asyncAfter(deadline: .now() + 3, execute: { [self] in
// 列表显示扫描到的设备
- self.showTableView()
+ showTableView()
})
} else {
AlertHub.shared.showWaringAlert(controller: self, message: "蓝牙不可用,请检查")
@@ -203,25 +207,30 @@
centralManager.stopScan()
LoadingHub.shared.hideLoading()
- let actionSheetController = UIAlertController()
- for device in scanDevices {
- actionSheetController.addAction(UIAlertAction(title: device.name, style: .default, handler: { [self] alertAction in
- // 连接点击的设备
- LoadingHub.shared.showLoading(text: "设备连接中...")
- scanDevices.forEach { it in
- if alertAction.title == it.name {
- centralManager.connect(it, options: nil)
+ if scanDevices.count == 0 {
+ AlertHub.shared.showWaringAlert(controller: self, message: "无可用设备,请确认设备是否已开启")
+ } else {
+ let actionSheetController = UIAlertController()
+ for device in scanDevices {
+ actionSheetController.addAction(UIAlertAction(title: device.name, style: .default, handler: { [self] alertAction in
+ // 连接点击的设备
+ LoadingHub.shared.showLoading(text: "设备连接中...")
+ scanDevices.forEach { it in
+ if alertAction.title == it.name {
+ centralManager.connect(it, options: nil)
+ }
}
- }
- }))
+ }))
+ }
+ actionSheetController.addAction(UIAlertAction(title: "取消", style: .cancel))
+ present(actionSheetController, animated: true, completion: nil)
}
- actionSheetController.addAction(UIAlertAction(title: "取消", style: .cancel))
- present(actionSheetController, animated: true, completion: nil)
}
// 重新发送指令
@IBAction func refreshCmdAction(_ sender: Any) {
if isBluetoothAvailable() {
+ writeToPeripheral(OPEN_TRANSFER_COMMAND)
} else {
AlertHub.shared.showWaringAlert(controller: self, message: "请先连接设备")
}
@@ -232,7 +241,7 @@
view.addSubview(currentView)
currentView.snp.makeConstraints { (make) -> Void in
make.size.equalTo(CGSize(width: viewWidth, height: viewHeight))
- make.bottom.equalTo(-(SCREEN_HEIGHT * 0.1 + 10))
+ make.bottom.equalTo(-(SCREEN_HEIGHT * 0.1 + 20))
make.left.equalTo(10)
}
@@ -240,7 +249,7 @@
view.addSubview(settingView)
settingView.snp.makeConstraints { (make) -> Void in
make.size.equalTo(CGSize(width: viewWidth, height: viewHeight))
- make.bottom.equalTo(-(SCREEN_HEIGHT * 0.1 + 10))
+ make.bottom.equalTo(-(SCREEN_HEIGHT * 0.1 + 20))
make.centerX.equalToSuperview()
}
@@ -248,7 +257,7 @@
view.addSubview(maxView)
maxView.snp.makeConstraints { (make) -> Void in
make.size.equalTo(CGSize(width: viewWidth, height: viewHeight))
- make.bottom.equalTo(-(SCREEN_HEIGHT * 0.1 + 10))
+ make.bottom.equalTo(-(SCREEN_HEIGHT * 0.1 + 20))
make.right.equalTo(-10)
}
@@ -270,14 +279,29 @@
inputTextField = textField
inputTextField.delegate = self
}
- let actionOK = UIAlertAction(title: "保存", style: .default) { [self] (_: UIAlertAction) -> Void in
+ let actionOK = UIAlertAction(title: "开始巡检", style: .default) { [self] (_: UIAlertAction) -> Void in
if inputTextField.text == "" {
AlertHub.shared.showWaringAlert(controller: self, message: "巡检标签不能为空")
return
}
+ // 获取当前时间戳
+ let timeInterval: TimeInterval = Date().timeIntervalSince1970
+ let timeStamp = Int(timeInterval)
+ // 新建巡检,inspectionId必为空
+ inspectionId = timeStamp.id()
+ print("巡检id: \(inspectionId!)")
+ // 设置标题和时间
inspectNameLabel.text = inputTextField.text!
+ let dateformatter = DateFormatter()
+ dateformatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
+ inspectTimeLabel.text = dateformatter.string(from: Date(timeIntervalSince1970: timeInterval))
+
+ //开始巡检
+ startInspection()
}
- let actionCancel = UIAlertAction(title: "取消", style: .cancel, handler: nil)
+ let actionCancel = UIAlertAction(title: "放弃", style: .cancel) { [self] (_: UIAlertAction) -> Void in
+ navigationController?.popViewController(animated: true)
+ }
// 设置取消按钮颜色为红色
actionCancel.setValue(UIColor(red: 255 / 255, green: 0 / 255, blue: 0 / 255, alpha: 1), forKey: "titleTextColor")
msgAlertCtr.addAction(actionOK)
@@ -285,6 +309,10 @@
present(msgAlertCtr, animated: true, completion: nil)
}
+ func startInspection() {
+ //巡检主要就是记录巡检员的位置
+ }
+
@IBAction func addEventAction(_ sender: Any) {
let lng = keychain[Constant.CurrentLongitude.rawValue]! as String
let lat = keychain[Constant.CurrentLatitude.rawValue]! as String
@@ -294,15 +322,13 @@
// 委托代理
valueDelegate = newEventViewController
let selectController = UIAlertController(title: "选择事件类型", message: nil, preferredStyle: .alert)
- // 获取当前时间戳
- let timeInterval: TimeInterval = Date().timeIntervalSince1970
- let timeStamp = Int(timeInterval)
+
let inspectButton = UIAlertAction(title: "报警事件", style: .default, handler: { [self] _ in
// 实现代理的方法,传值
valueDelegate.transfer(controller: self,
dic: ["isWarning": true,
- "inspectionId": timeStamp.id(),
- "inspectionName": inspectNameLabel.text,
+ "inspectionId": inspectionId!,
+ "inspectionName": inspectNameLabel.text!,
"longitude": Double(lng)!,
"latitude": Double(lat)!])
navigationController?.pushViewController(newEventViewController, animated: true)
@@ -311,8 +337,8 @@
// 实现代理的方法,传值
valueDelegate.transfer(controller: self,
dic: ["isWarning": false,
- "inspectionId": timeStamp.id(),
- "inspectionName": inspectNameLabel.text,
+ "inspectionId": inspectionId!,
+ "inspectionName": inspectNameLabel.text!,
"longitude": Double(lng)!,
"latitude": Double(lat)!])
navigationController?.pushViewController(newEventViewController, animated: true)
@@ -509,7 +535,5 @@
}
}
-
extension MapViewController: UITextFieldDelegate {
-
}
diff --git a/LaserMethane/ViewController/Map/MapViewController.xib b/LaserMethane/ViewController/Map/MapViewController.xib
index c26493d..f26cb08 100644
--- a/LaserMethane/ViewController/Map/MapViewController.xib
+++ b/LaserMethane/ViewController/Map/MapViewController.xib
@@ -112,7 +112,7 @@
-
+
@@ -120,7 +120,7 @@
-
+