From e7e89922fe70319e22f9fa2992307cd84af33dbf Mon Sep 17 00:00:00 2001 From: leeway Date: Sat, 13 Nov 2021 11:34:10 +0800 Subject: [PATCH] fix MqttAuthProperties lose import Foundation bug --- CocoaMQTT.podspec | 4 ++-- README.md | 2 +- Source/CocoaMQTT.swift | 28 +++++++++++++--------------- Source/CocoaMQTT5.swift | 16 ++++++++-------- Source/CocoaMQTTMessage.swift | 1 - Source/CocoaMQTTProperty.swift | 1 - Source/CocoaMQTTTypes.swift | 1 - Source/Frame.swift | 1 - Source/FrameAuth.swift | 1 - Source/FrameConnAck.swift | 1 - Source/FrameDisconnect.swift | 1 - Source/FramePingResp.swift | 1 - Source/FramePubAck.swift | 1 - Source/FrameSubAck.swift | 1 - Source/FrameSubscribe.swift | 1 - Source/FrameUnsubscribe.swift | 1 - Source/MqttAuthProperties.swift | 1 + Source/MqttDecodeConnAck.swift | 12 ------------ Source/MqttDecodePubAck.swift | 1 - Source/MqttDecodePubComp.swift | 1 - Source/MqttDecodePubRel.swift | 1 - Source/MqttDecodeSubAck.swift | 1 - Source/MqttDecodeUnsubAck.swift | 1 - Source/MqttPublishProperties.swift | 1 - Source/MqttSubscription.swift | 4 +--- 25 files changed, 26 insertions(+), 59 deletions(-) diff --git a/CocoaMQTT.podspec b/CocoaMQTT.podspec index f6777348..94813e29 100644 --- a/CocoaMQTT.podspec +++ b/CocoaMQTT.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "CocoaMQTT" - s.version = "2.0.0" + s.version = "2.0.1" s.summary = "MQTT v3.1.1 client library for iOS and OS X written with Swift 5" s.homepage = "https://github.com/emqx/CocoaMQTT" s.license = { :type => "MIT" } @@ -12,7 +12,7 @@ Pod::Spec.new do |s| s.ios.deployment_target = "10.0" s.tvos.deployment_target = "10.0" # s.watchos.deployment_target = "2.0" - s.source = { :git => "https://github.com/emqx/CocoaMQTT.git", :tag => "2.0.0"} + s.source = { :git => "https://github.com/emqx/CocoaMQTT.git", :tag => "2.0.1"} s.default_subspec = 'Core' s.subspec 'Core' do |ss| diff --git a/README.md b/README.md index 4151a31e..3f13492d 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ TVOS Target: 10.0 or above Install using [CocoaPods](http://cocoapods.org) by adding this line to your Podfile: ```ruby -pod 'CocoaMQTT, '~> 2.0.0'' +pod 'CocoaMQTT, '~> 2.0.1'' ``` Then, run the following command: diff --git a/Source/CocoaMQTT.swift b/Source/CocoaMQTT.swift index 85f787fc..e4a71be6 100644 --- a/Source/CocoaMQTT.swift +++ b/Source/CocoaMQTT.swift @@ -9,8 +9,6 @@ import Foundation import CocoaAsyncSocket - - /** * Conn Ack */ @@ -25,13 +23,13 @@ import CocoaAsyncSocket public var description: String { switch self { - case .accept: return "accept" - case .unacceptableProtocolVersion: return "unacceptableProtocolVersion" - case .identifierRejected: return "identifierRejected" - case .serverUnavailable: return "serverUnavailable" - case .badUsernameOrPassword: return "badUsernameOrPassword" - case .notAuthorized: return "notAuthorized" - case .reserved: return "reserved" + case .accept: return "accept" + case .unacceptableProtocolVersion: return "unacceptableProtocolVersion" + case .identifierRejected: return "identifierRejected" + case .serverUnavailable: return "serverUnavailable" + case .badUsernameOrPassword: return "badUsernameOrPassword" + case .notAuthorized: return "notAuthorized" + case .reserved: return "reserved" } } } @@ -516,7 +514,7 @@ extension CocoaMQTT: CocoaMQTTDeliverProtocol { self.delegate?.mqtt(self, didPublishMessage: message, id: msgid) self.didPublishMessage(self, message, msgid) - + } else if let pubrel = frame as? FramePubRel { // -- Send PUBREL send(pubrel, tag: Int(pubrel.msgid)) @@ -542,8 +540,8 @@ extension CocoaMQTT: CocoaMQTTSocketDelegate { } public func socket(_ socket: CocoaMQTTSocketProtocol, - didReceive trust: SecTrust, - completionHandler: @escaping (Bool) -> Swift.Void) { + didReceive trust: SecTrust, + completionHandler: @escaping (Bool) -> Swift.Void) { printDebug("Call the SSL/TLS manually validating function") @@ -589,7 +587,7 @@ extension CocoaMQTT: CocoaMQTTSocketDelegate { } } - guard autoReconnect else { + guard autoReconnect else { return } @@ -615,7 +613,7 @@ extension CocoaMQTT: CocoaMQTTSocketDelegate { extension CocoaMQTT: CocoaMQTTReaderDelegate { func didReceive(_ reader: CocoaMQTTReader, disconnect: FrameDisconnect) { - + } func didReceive(_ reader: CocoaMQTTReader, auth: FrameAuth) { @@ -746,7 +744,7 @@ extension CocoaMQTT: CocoaMQTTReaderDelegate { delegate?.mqtt(self, didSubscribeTopics: success, failed: failed) didSubscribeTopics(self, success, failed) } - + func didReceive(_ reader: CocoaMQTTReader, unsuback: FrameUnsubAck) { printDebug("RECV: \(unsuback)") diff --git a/Source/CocoaMQTT5.swift b/Source/CocoaMQTT5.swift index f2467302..776aeb2c 100644 --- a/Source/CocoaMQTT5.swift +++ b/Source/CocoaMQTT5.swift @@ -19,9 +19,9 @@ import CocoaAsyncSocket public var description: String { switch self { - case .connecting: return "connecting" - case .connected: return "connected" - case .disconnected: return "disconnected" + case .connecting: return "connecting" + case .connected: return "connected" + case .disconnected: return "disconnected" } } } @@ -319,7 +319,7 @@ public class CocoaMQTT5: NSObject, CocoaMQTT5Client { fileprivate func send(_ frame: Frame, tag: Int = 0) { printDebug("SEND: \(frame)") let data = frame.bytes(version: version) - + socket.write(Data(bytes: data, count: data.count), withTimeout: 5, tag: tag) } @@ -449,7 +449,7 @@ public class CocoaMQTT5: NSObject, CocoaMQTT5Client { /// - -1 will be returned, if the messages queue is full @discardableResult public func publish(_ topic: String, withString string: String, qos: CocoaMQTTQoS = .qos1, DUP: Bool = false -, retained: Bool = false, properties: MqttPublishProperties) -> Int { + , retained: Bool = false, properties: MqttPublishProperties) -> Int { let message = CocoaMQTT5Message(topic: topic, string: string, qos: qos, retained: retained) return publish(message, DUP: DUP, retained: retained, properties: properties) } @@ -589,8 +589,8 @@ extension CocoaMQTT5: CocoaMQTTSocketDelegate { } public func socket(_ socket: CocoaMQTTSocketProtocol, - didReceive trust: SecTrust, - completionHandler: @escaping (Bool) -> Swift.Void) { + didReceive trust: SecTrust, + completionHandler: @escaping (Bool) -> Swift.Void) { printDebug("Call the SSL/TLS manually validating function") @@ -627,7 +627,7 @@ extension CocoaMQTT5: CocoaMQTTSocketDelegate { // Clean up socket.setDelegate(nil, delegateQueue: nil) connState = .disconnected - + delegate?.mqtt5DidDisconnect(self, withError: err) didDisconnect(self, err) diff --git a/Source/CocoaMQTTMessage.swift b/Source/CocoaMQTTMessage.swift index b516f5a0..e1a7cb7f 100644 --- a/Source/CocoaMQTTMessage.swift +++ b/Source/CocoaMQTTMessage.swift @@ -8,7 +8,6 @@ import Foundation - /// MQTT Message public class CocoaMQTTMessage: NSObject { diff --git a/Source/CocoaMQTTProperty.swift b/Source/CocoaMQTTProperty.swift index fe4bc3f8..e8ac8cfc 100644 --- a/Source/CocoaMQTTProperty.swift +++ b/Source/CocoaMQTTProperty.swift @@ -7,7 +7,6 @@ import Foundation - public enum CocoaMQTTPropertyName: UInt8 { case payloadFormatIndicator = 0x01 case willExpiryInterval = 0x02 diff --git a/Source/CocoaMQTTTypes.swift b/Source/CocoaMQTTTypes.swift index dce48996..4c465e99 100644 --- a/Source/CocoaMQTTTypes.swift +++ b/Source/CocoaMQTTTypes.swift @@ -8,7 +8,6 @@ import Foundation - /// Encode and Decode big-endian UInt16 extension UInt16 { /// Most Significant Byte (MSB) diff --git a/Source/Frame.swift b/Source/Frame.swift index a9e83800..1dc9b8b2 100644 --- a/Source/Frame.swift +++ b/Source/Frame.swift @@ -8,7 +8,6 @@ import Foundation - /// Quality of Service levels @objc public enum CocoaMQTTQoS: UInt8, CustomStringConvertible { /// At most once delivery diff --git a/Source/FrameAuth.swift b/Source/FrameAuth.swift index 88d17a61..c50ef0fe 100644 --- a/Source/FrameAuth.swift +++ b/Source/FrameAuth.swift @@ -7,7 +7,6 @@ import Foundation - struct FrameAuth: Frame { var packetFixedHeaderType: UInt8 = FrameType.auth.rawValue diff --git a/Source/FrameConnAck.swift b/Source/FrameConnAck.swift index 82cbf054..29bdc8cd 100644 --- a/Source/FrameConnAck.swift +++ b/Source/FrameConnAck.swift @@ -8,7 +8,6 @@ import Foundation - struct FrameConnAck: Frame { var packetFixedHeaderType: UInt8 = FrameType.connack.rawValue diff --git a/Source/FrameDisconnect.swift b/Source/FrameDisconnect.swift index b2fb6ea1..b110d937 100644 --- a/Source/FrameDisconnect.swift +++ b/Source/FrameDisconnect.swift @@ -8,7 +8,6 @@ import Foundation - /// MQTT Disconnect packet struct FrameDisconnect: Frame { diff --git a/Source/FramePingResp.swift b/Source/FramePingResp.swift index f527e800..aa46074f 100644 --- a/Source/FramePingResp.swift +++ b/Source/FramePingResp.swift @@ -8,7 +8,6 @@ import Foundation - /// MQTT PINGRESP packet struct FramePingResp: Frame { diff --git a/Source/FramePubAck.swift b/Source/FramePubAck.swift index b6434b7c..54923b1a 100644 --- a/Source/FramePubAck.swift +++ b/Source/FramePubAck.swift @@ -8,7 +8,6 @@ import Foundation - /// MQTT PUBACK packet struct FramePubAck: Frame { diff --git a/Source/FrameSubAck.swift b/Source/FrameSubAck.swift index 179de5f6..106059ce 100644 --- a/Source/FrameSubAck.swift +++ b/Source/FrameSubAck.swift @@ -8,7 +8,6 @@ import Foundation - /// MQTT SUBACK packet struct FrameSubAck: Frame { diff --git a/Source/FrameSubscribe.swift b/Source/FrameSubscribe.swift index d3a488d5..48182f98 100644 --- a/Source/FrameSubscribe.swift +++ b/Source/FrameSubscribe.swift @@ -8,7 +8,6 @@ import Foundation - /// MQTT SUBSCRIBE Frame struct FrameSubscribe: Frame { diff --git a/Source/FrameUnsubscribe.swift b/Source/FrameUnsubscribe.swift index 761d6c04..0d472829 100644 --- a/Source/FrameUnsubscribe.swift +++ b/Source/FrameUnsubscribe.swift @@ -8,7 +8,6 @@ import Foundation - /// MQTT UNSUBSCRIBE packet struct FrameUnsubscribe: Frame { diff --git a/Source/MqttAuthProperties.swift b/Source/MqttAuthProperties.swift index 9b215ab4..f50e4e3b 100644 --- a/Source/MqttAuthProperties.swift +++ b/Source/MqttAuthProperties.swift @@ -5,6 +5,7 @@ // Created by liwei wang on 1/9/2021. // +import Foundation public class MqttAuthProperties: NSObject { diff --git a/Source/MqttDecodeConnAck.swift b/Source/MqttDecodeConnAck.swift index f54f0a3d..73088107 100644 --- a/Source/MqttDecodeConnAck.swift +++ b/Source/MqttDecodeConnAck.swift @@ -7,7 +7,6 @@ import Foundation - public class MqttDecodeConnAck: NSObject { // var connackData: [UInt8] @@ -65,7 +64,6 @@ public class MqttDecodeConnAck: NSObject { let occupyIndex = index // properties - while index - occupyIndex < propertyLength! { let resVariableByteInteger = decodeVariableByteInteger(data: connackData, offset: index) index = resVariableByteInteger.newOffset @@ -77,16 +75,12 @@ public class MqttDecodeConnAck: NSObject { switch propertyName.rawValue { case CocoaMQTTPropertyName.sessionExpiryInterval.rawValue: -// sessionExpiryInterval = UInt32(integerCompute(data: connackData, formatType: formatInt.formatUint32.rawValue, offset: index)!) -// index += 4 let comRes = integerCompute(data: connackData, formatType: formatInt.formatUint32.rawValue, offset: index) sessionExpiryInterval = UInt32(comRes!.res) index = comRes!.newOffset case CocoaMQTTPropertyName.receiveMaximum.rawValue: -// receiveMaximum = UInt16(integerCompute(data: connackData, formatType: formatInt.formatUint16.rawValue, offset: index)!) -// index += 2 let comRes = integerCompute(data: connackData, formatType: formatInt.formatUint16.rawValue, offset: index) receiveMaximum = UInt16(comRes!.res) @@ -117,8 +111,6 @@ public class MqttDecodeConnAck: NSObject { index += 1 case CocoaMQTTPropertyName.maximumPacketSize.rawValue: -// maximumPacketSize = UInt32(integerCompute(data: connackData, formatType: formatInt.formatUint32.rawValue, offset: index)!) -// index += 4 let comRes = integerCompute(data: connackData, formatType: formatInt.formatUint32.rawValue, offset: index) maximumPacketSize = UInt32(comRes!.res) @@ -132,8 +124,6 @@ public class MqttDecodeConnAck: NSObject { index = result.newOffset case CocoaMQTTPropertyName.topicAliasMaximum.rawValue: -// topicAliasMaximum = UInt16(integerCompute(data: connackData, formatType: formatInt.formatUint16.rawValue, offset: index)!) -// index += 2 let comRes = integerCompute(data: connackData, formatType: formatInt.formatUint16.rawValue, offset: index) topicAliasMaximum = UInt16(comRes!.res) @@ -197,8 +187,6 @@ public class MqttDecodeConnAck: NSObject { index += 1 case CocoaMQTTPropertyName.serverKeepAlive.rawValue: -// serverKeepAlive = UInt16(integerCompute(data: connackData, formatType: formatInt.formatUint16.rawValue, offset: index)!) -// index += 2 let comRes = integerCompute(data: connackData, formatType: formatInt.formatUint16.rawValue, offset: index) serverKeepAlive = UInt16(comRes!.res) diff --git a/Source/MqttDecodePubAck.swift b/Source/MqttDecodePubAck.swift index e3561377..78979372 100644 --- a/Source/MqttDecodePubAck.swift +++ b/Source/MqttDecodePubAck.swift @@ -7,7 +7,6 @@ import Foundation - public class MqttDecodePubAck: NSObject { var totalCount = 0 diff --git a/Source/MqttDecodePubComp.swift b/Source/MqttDecodePubComp.swift index 2e745201..d8543cb8 100644 --- a/Source/MqttDecodePubComp.swift +++ b/Source/MqttDecodePubComp.swift @@ -7,7 +7,6 @@ import Foundation - public class MqttDecodePubComp: NSObject { var totalCount = 0 diff --git a/Source/MqttDecodePubRel.swift b/Source/MqttDecodePubRel.swift index fccc9fbc..5145849d 100644 --- a/Source/MqttDecodePubRel.swift +++ b/Source/MqttDecodePubRel.swift @@ -7,7 +7,6 @@ import Foundation - public class MqttDecodePubRel: NSObject { var totalCount = 0 diff --git a/Source/MqttDecodeSubAck.swift b/Source/MqttDecodeSubAck.swift index 032504bd..efd6e870 100644 --- a/Source/MqttDecodeSubAck.swift +++ b/Source/MqttDecodeSubAck.swift @@ -7,7 +7,6 @@ import Foundation - public class MqttDecodeSubAck: NSObject { var totalCount = 0 diff --git a/Source/MqttDecodeUnsubAck.swift b/Source/MqttDecodeUnsubAck.swift index 03a21bd8..b9d56665 100644 --- a/Source/MqttDecodeUnsubAck.swift +++ b/Source/MqttDecodeUnsubAck.swift @@ -7,7 +7,6 @@ import Foundation - public class MqttDecodeUnsubAck: NSObject { var totalCount = 0 diff --git a/Source/MqttPublishProperties.swift b/Source/MqttPublishProperties.swift index 8812e44f..39608273 100644 --- a/Source/MqttPublishProperties.swift +++ b/Source/MqttPublishProperties.swift @@ -7,7 +7,6 @@ import Foundation - public class MqttPublishProperties: NSObject { diff --git a/Source/MqttSubscription.swift b/Source/MqttSubscription.swift index d077978c..6376c2f2 100644 --- a/Source/MqttSubscription.swift +++ b/Source/MqttSubscription.swift @@ -39,7 +39,7 @@ public class MqttSubscription { case .qos2: options = options | 0b0000_0010 default: - printDebug("topucFilter qos failure") + printDebug("topicFilter qos failure") } switch noLocal { @@ -63,8 +63,6 @@ public class MqttSubscription { options = options | 0b0001_0000 case CocoaRetainHandlingOption.sendOnSubscribe: options = options | 0b0010_0000 -// default: -// printDebug("topucFilter retainHandling failure") }