Skip to content

Commit

Permalink
Pod supspec
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurgau0419 committed Oct 19, 2020
1 parent 34d5999 commit 5043fc5
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
13 changes: 11 additions & 2 deletions CocoaMQTT.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions Example/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 12 additions & 2 deletions Source/CocoaMQTT.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
3 changes: 2 additions & 1 deletion Source/CocoaMQTTNetworkConnectionSocket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Copyright © 2020 emqx.io. All rights reserved.
//

#if canImport(Network)
import Foundation
import Network

Expand Down Expand Up @@ -106,4 +107,4 @@ extension CocoaMQTTNetworkConnectionSocket {
return NWParameters(tls: options)
}
}

#endif
6 changes: 6 additions & 0 deletions Source/CocoaMQTTSocket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
//

import Foundation
#if canImport(CocoaAsyncSocket)
import CocoaAsyncSocket
#endif

// MARK: - Interfaces

Expand All @@ -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 {
Expand Down Expand Up @@ -133,3 +136,6 @@ extension CocoaMQTTSocket: GCDAsyncSocketDelegate {
delegate?.socketDidDisconnect(self, withError: err)
}
}
#elseif canImport(Network)
public typealias CocoaMQTTSocket = CocoaMQTTNetworkConnectionSocket
#endif

0 comments on commit 5043fc5

Please sign in to comment.