GeminiProtocl: Fix attribution not being set, and not compiling on macOS
This commit is contained in:
parent
c59fe5b319
commit
a9327249eb
|
@ -19,6 +19,7 @@ public class GeminiDataTask {
|
||||||
private let connection: NWConnection
|
private let connection: NWConnection
|
||||||
// todo: remove stupid hack when deployment target is >= iOS 15/macOS 12
|
// todo: remove stupid hack when deployment target is >= iOS 15/macOS 12
|
||||||
private var _attribution: Any? = nil
|
private var _attribution: Any? = nil
|
||||||
|
#if os(iOS)
|
||||||
@available(iOS 15.0, *)
|
@available(iOS 15.0, *)
|
||||||
public var attribution: NWParameters.Attribution {
|
public var attribution: NWParameters.Attribution {
|
||||||
get {
|
get {
|
||||||
|
@ -28,6 +29,7 @@ public class GeminiDataTask {
|
||||||
_attribution = newValue
|
_attribution = newValue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
public init(request: GeminiRequest, completion: @escaping Completion) {
|
public init(request: GeminiRequest, completion: @escaping Completion) {
|
||||||
self.request = request
|
self.request = request
|
||||||
|
@ -36,10 +38,6 @@ public class GeminiDataTask {
|
||||||
let endpoint: NWEndpoint = .hostPort(host: NWEndpoint.Host(request.url.host!), port: NWEndpoint.Port(rawValue: port)!)
|
let endpoint: NWEndpoint = .hostPort(host: NWEndpoint.Host(request.url.host!), port: NWEndpoint.Port(rawValue: port)!)
|
||||||
self.connection = NWConnection(to: endpoint, using: .gemini)
|
self.connection = NWConnection(to: endpoint, using: .gemini)
|
||||||
|
|
||||||
if #available(iOS 15.0, *) {
|
|
||||||
connection.parameters.attribution = attribution
|
|
||||||
}
|
|
||||||
|
|
||||||
self.connection.stateUpdateHandler = { (newState) in
|
self.connection.stateUpdateHandler = { (newState) in
|
||||||
switch newState {
|
switch newState {
|
||||||
case .ready:
|
case .ready:
|
||||||
|
@ -65,6 +63,13 @@ public class GeminiDataTask {
|
||||||
|
|
||||||
public func resume() {
|
public func resume() {
|
||||||
guard state == .unstarted else { return }
|
guard state == .unstarted else { return }
|
||||||
|
|
||||||
|
#if os(iOS)
|
||||||
|
if #available(iOS 15.0, *) {
|
||||||
|
connection.parameters.attribution = attribution
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
state = .started
|
state = .started
|
||||||
connection.start(queue: GeminiDataTask.queue)
|
connection.start(queue: GeminiDataTask.queue)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue