diff --git a/CocoaMQTT.podspec b/CocoaMQTT.podspec index 8cebd96f..f8965503 100644 --- a/CocoaMQTT.podspec +++ b/CocoaMQTT.podspec @@ -13,13 +13,22 @@ Pod::Spec.new do |s| s.tvos.deployment_target = "10.0" # s.watchos.deployment_target = "2.0" s.source = { :git => "https://github.com/emqx/CocoaMQTT.git", :tag => "1.3.0-rc.1"} - s.default_subspec = 'Core' + s.default_subspecs = ['Core', 'CocoaAsyncSocket'] s.subspec 'Core' do |ss| - ss.dependency "CocoaAsyncSocket", "~> 7.6.3" ss.source_files = "Source/*.swift" ss.exclude_files = "Source/CocoaMQTTWebSocket.swift" end + + s.subspec 'Network' do |ss| + ss.dependency "CocoaMQTT/Core" + ss.framework = "Network" + end + + s.subspec 'CocoaAsyncSocket' do |ss| + ss.dependency "CocoaMQTT/Core" + ss.dependency "CocoaAsyncSocket", "~> 7.6.3" + end s.subspec 'WebSockets' do |ss| ss.dependency "CocoaMQTT/Core" diff --git a/Example/Podfile b/Example/Podfile index fa9c4da4..411dc130 100644 --- a/Example/Podfile +++ b/Example/Podfile @@ -2,5 +2,7 @@ platform :ios, 10.0 use_frameworks! target 'Example' do + pod 'CocoaMQTT', :path => '../' pod 'CocoaMQTT/WebSockets', :path => '../' + pod 'CocoaMQTT/CocoaAsyncSocket', :path => '../' end diff --git a/Source/CocoaMQTT.swift b/Source/CocoaMQTT.swift index 3f9b2708..4f768335 100644 --- a/Source/CocoaMQTT.swift +++ b/Source/CocoaMQTT.swift @@ -163,8 +163,18 @@ public class CocoaMQTT: NSObject, CocoaMQTTClient { /// /// - Note: public var backgroundOnSocket: Bool { - get { return (self.socket as? CocoaMQTTSocket)?.backgroundOnSocket ?? true } - set { (self.socket as? CocoaMQTTSocket)?.backgroundOnSocket = newValue } + get { + #if canImport(CocoaAsyncSocket) + return (self.socket as? CocoaMQTTSocket)?.backgroundOnSocket ?? true + #else + return true + #endif + } + set { + #if canImport(CocoaAsyncSocket) + (self.socket as? CocoaMQTTSocket)?.backgroundOnSocket = newValue + #endif + } } /// Delegate Executed queue. Default is `DispatchQueue.main` diff --git a/Source/CocoaMQTTNetworkConnectionSocket.swift b/Source/CocoaMQTTNetworkConnectionSocket.swift index abf08dac..86a9931c 100644 --- a/Source/CocoaMQTTNetworkConnectionSocket.swift +++ b/Source/CocoaMQTTNetworkConnectionSocket.swift @@ -6,6 +6,7 @@ // Copyright © 2020 emqx.io. All rights reserved. // +#if canImport(Network) import Foundation import Network @@ -106,4 +107,4 @@ extension CocoaMQTTNetworkConnectionSocket { return NWParameters(tls: options) } } - +#endif diff --git a/Source/CocoaMQTTSocket.swift b/Source/CocoaMQTTSocket.swift index 5ea0bf76..8e11febf 100644 --- a/Source/CocoaMQTTSocket.swift +++ b/Source/CocoaMQTTSocket.swift @@ -6,7 +6,9 @@ // import Foundation +#if canImport(CocoaAsyncSocket) import CocoaAsyncSocket +#endif // MARK: - Interfaces @@ -30,6 +32,7 @@ public protocol CocoaMQTTSocketProtocol { func write(_ data: Data, withTimeout timeout: TimeInterval, tag: Int) } +#if canImport(CocoaAsyncSocket) // MARK: - CocoaMQTTSocket public class CocoaMQTTSocket: NSObject { @@ -133,3 +136,6 @@ extension CocoaMQTTSocket: GCDAsyncSocketDelegate { delegate?.socketDidDisconnect(self, withError: err) } } +#elseif canImport(Network) +public typealias CocoaMQTTSocket = CocoaMQTTNetworkConnectionSocket +#endif