Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/HuaZao/TC1-NG
Browse files Browse the repository at this point in the history
# Conflicts:
#	TC1-NG/Controller/Device/TCDeviceInfoTableViewController.swift
  • Loading branch information
神奇海螺 committed May 22, 2019
2 parents 68c1ac8 + d3e093b commit 89476be
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: e74c7a9538c5d8d2407598ab95f3904f318dd378

COCOAPODS: 1.5.3
COCOAPODS: 1.6.0
4 changes: 2 additions & 2 deletions TC1-NG.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@
files = (
);
inputPaths = (
"${SRCROOT}/Pods/Target Support Files/Pods-TC1-NG/Pods-TC1-NG-frameworks.sh",
"${PODS_ROOT}/Target Support Files/Pods-TC1-NG/Pods-TC1-NG-frameworks.sh",
"${BUILT_PRODUCTS_DIR}/Bitter/Bitter.framework",
"${BUILT_PRODUCTS_DIR}/CocoaAsyncSocket/CocoaAsyncSocket.framework",
"${BUILT_PRODUCTS_DIR}/FMDB/FMDB.framework",
Expand All @@ -339,7 +339,7 @@
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-TC1-NG/Pods-TC1-NG-frameworks.sh\"\n";
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-TC1-NG/Pods-TC1-NG-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
8B535F4303A9A33CF13C3851 /* [CP] Check Pods Manifest.lock */ = {
Expand Down
66 changes: 62 additions & 4 deletions TC1-NG/Base.lproj/TCDeviceMain.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -755,8 +755,8 @@
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<view key="tableFooterView" contentMode="scaleToFill" id="4P6-C7-WUp">
<rect key="frame" x="0.0" y="220" width="375" height="0.0"/>
<view key="tableFooterView" contentMode="scaleToFill" id="2l3-GO-Hbf">
<rect key="frame" x="0.0" y="308" width="375" height="0.0"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
Expand Down Expand Up @@ -841,9 +841,35 @@
</tableViewCellContentView>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" accessoryType="disclosureIndicator" indentationWidth="10" textLabel="yxn-fJ-OJg" detailTextLabel="sB1-Se-ZoN" style="IBUITableViewCellStyleValue1" id="uDs-pP-R0I">
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" indentationWidth="10" textLabel="nwR-1y-bCo" detailTextLabel="uja-qK-VuE" style="IBUITableViewCellStyleValue1" id="ebP-Mv-3Dm">
<rect key="frame" x="0.0" y="132" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="ebP-Mv-3Dm" id="JYf-ly-Fzn">
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="连接方式" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="nwR-1y-bCo">
<rect key="frame" x="16" y="12" width="69.5" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="-----" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="uja-qK-VuE">
<rect key="frame" x="320.5" y="12" width="38.5" height="20.5"/>
<autoresizingMask key="autoresizingMask"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<color key="textColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<color key="backgroundColor" white="1" alpha="0.5" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</tableViewCellContentView>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" accessoryType="disclosureIndicator" indentationWidth="10" textLabel="yxn-fJ-OJg" detailTextLabel="sB1-Se-ZoN" style="IBUITableViewCellStyleValue1" id="uDs-pP-R0I">
<rect key="frame" x="0.0" y="176" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="uDs-pP-R0I" id="JeO-Co-BOC">
<rect key="frame" x="0.0" y="0.0" width="341" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
Expand Down Expand Up @@ -871,7 +897,7 @@
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" accessoryType="disclosureIndicator" indentationWidth="10" textLabel="b6H-HF-WZm" detailTextLabel="A1W-sl-khb" style="IBUITableViewCellStyleValue1" id="xjT-1I-fly">
<rect key="frame" x="0.0" y="176" width="375" height="44"/>
<rect key="frame" x="0.0" y="220" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="xjT-1I-fly" id="SLs-bq-oys">
<rect key="frame" x="0.0" y="0.0" width="341" height="43.5"/>
Expand All @@ -896,6 +922,36 @@
</tableViewCellContentView>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" indentationWidth="10" id="Ugs-hg-JeE">
<rect key="frame" x="0.0" y="264" width="375" height="44"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="Ugs-hg-JeE" id="22v-eg-sAB">
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="强制使用MQTT" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="buV-Hk-iwk">
<rect key="frame" x="16" y="11.5" width="117" height="21"/>
<fontDescription key="fontDescription" type="system" pointSize="17"/>
<nil key="textColor"/>
<nil key="highlightedColor"/>
</label>
<switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" translatesAutoresizingMaskIntoConstraints="NO" id="w9d-Jv-VPK">
<rect key="frame" x="308" y="6.5" width="51" height="31"/>
<connections>
<action selector="alwaysUseMQTTAction:" destination="Yq7-oc-i6P" eventType="valueChanged" id="jMz-hF-4jn"/>
</connections>
</switch>
</subviews>
<color key="backgroundColor" white="1" alpha="0.5" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<constraints>
<constraint firstItem="buV-Hk-iwk" firstAttribute="leading" secondItem="22v-eg-sAB" secondAttribute="leadingMargin" id="LG8-8I-tEf"/>
<constraint firstAttribute="trailing" secondItem="w9d-Jv-VPK" secondAttribute="trailing" constant="18" id="dUD-Vn-tF9"/>
<constraint firstItem="buV-Hk-iwk" firstAttribute="centerY" secondItem="22v-eg-sAB" secondAttribute="centerY" id="eKQ-L1-sNN"/>
<constraint firstItem="w9d-Jv-VPK" firstAttribute="centerY" secondItem="22v-eg-sAB" secondAttribute="centerY" id="sy7-Rs-qmY"/>
</constraints>
</tableViewCellContentView>
<color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</tableViewCell>
</cells>
</tableViewSection>
</sections>
Expand All @@ -918,8 +974,10 @@
</barButtonItem>
</navigationItem>
<connections>
<outlet property="connectLabel" destination="uja-qK-VuE" id="af4-a0-xSg"/>
<outlet property="deviceName" destination="mn8-Ft-iTe" id="Zeh-lH-gmz"/>
<outlet property="ipAddress" destination="y4X-4T-ge6" id="PqP-jZ-8OZ"/>
<outlet property="isMQTT" destination="w9d-Jv-VPK" id="Wft-cj-c8X"/>
<outlet property="macAddress" destination="qzo-hR-5yz" id="Cqj-TK-NPz"/>
<outlet property="mqttAddress" destination="sB1-Se-ZoN" id="VLd-6a-maN"/>
<outlet property="version" destination="A1W-sl-khb" id="0xD-iQ-ZPg"/>
Expand Down
23 changes: 22 additions & 1 deletion TC1-NG/Controller/Device/TCDeviceInfoTableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ class TCDeviceInfoTableViewController: UITableViewController {
@IBOutlet weak var mqttAddress: UILabel!
@IBOutlet weak var version: UILabel!
@IBOutlet weak var deviceName: UILabel!
@IBOutlet weak var connectLabel: UILabel!
@IBOutlet weak var isMQTT: UISwitch!

var deviceModel = TCDeviceModel()

Expand All @@ -27,8 +29,14 @@ class TCDeviceInfoTableViewController: UITableViewController {
self.mqttAddress.text = self.deviceModel.host
self.version.text = self.deviceModel.version
self.deviceName.text = self.deviceModel.name
self.isMQTT.isOn = self.deviceModel.isOnline
TC1ServiceManager.share.delegate = self
TC1ServiceManager.share.subscribeDeviceMessage()
if TC1ServiceManager.share.isLocal{
self.connectLabel.text = "UDP"
}else{
self.connectLabel.text = "MQTT"
}
self.tableView.reloadData()
}

Expand All @@ -49,6 +57,19 @@ class TCDeviceInfoTableViewController: UITableViewController {
}
}


@IBAction func alwaysUseMQTTAction(_ sender: UISwitch) {
if self.deviceModel.host != ""{
self.deviceModel.isOnline = sender.isOn
TCSQLManager.updateTCDevice(self.deviceModel)
HUD.flash(.labeledSuccess(title: "设置成功", subtitle: "重新打开APP之后生效!"), delay: 1)
}else{
if sender.isOn{
HUD.flash(HUDContentType.labeledError(title: "无法设置", subtitle: "MQTT服务端尚未设置!"), delay: 1)
}
}
}

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.row == 0{
let alert = UIAlertController(title: "重命名", message: "请输入新名字", preferredStyle: .alert)
Expand All @@ -70,7 +91,7 @@ class TCDeviceInfoTableViewController: UITableViewController {
})
alert.addAction(reNameAction)
self.present(alert, animated: true, completion: nil)
}else if indexPath.row == 4{
}else if indexPath.row == 5{
self.checkForUpdates()
}else if indexPath.row == 1 || indexPath.row == 2{
if let cell = tableView.cellForRow(at: indexPath),let content = cell.textLabel?.text{
Expand Down
8 changes: 7 additions & 1 deletion TC1-NG/TC1ServiceManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ class TC1ServiceManager: NSObject {
//不传入设备则代表使用UDP广播
//ip用于判断使用UDP还是MQTT
func connectService(device:TCDeviceModel? = nil,ip:String? = nil){
if device?.isOnline == true{
print("当前强制MQTT环境")
self.initTC1MQTTService(device: device)
return
}
self.isLan(ip: ip) { [unowned self] (isLocal) in
self.isLocal = isLocal
if isLocal{
print("当前为局域网环境")
self.initTC1UDPService()
Expand Down Expand Up @@ -86,6 +90,7 @@ class TC1ServiceManager: NSObject {
guard device.port != 0 else{
return
}
self.isLocal = false
self.mac = device.mac
let transport = MQTTCFSocketTransport()
transport.host = device.host
Expand All @@ -106,6 +111,7 @@ class TC1ServiceManager: NSObject {
}

private func initTC1UDPService(){
self.isLocal = true
self.udpSocket = GCDAsyncUdpSocket(delegate: self, delegateQueue: DispatchQueue.global())
do {
try self.udpSocket?.enableBroadcast(true)
Expand Down

0 comments on commit 89476be

Please sign in to comment.