GeminiProtocl: Fix attribution not being set, and not compiling on macOS

This commit is contained in:
Shadowfacts 2021-10-01 19:25:54 -04:00
parent c59fe5b319
commit a9327249eb
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 9 additions and 4 deletions

View File

@ -19,6 +19,7 @@ public class GeminiDataTask {
private let connection: NWConnection
// todo: remove stupid hack when deployment target is >= iOS 15/macOS 12
private var _attribution: Any? = nil
#if os(iOS)
@available(iOS 15.0, *)
public var attribution: NWParameters.Attribution {
get {
@ -28,6 +29,7 @@ public class GeminiDataTask {
_attribution = newValue
}
}
#endif
public init(request: GeminiRequest, completion: @escaping Completion) {
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)!)
self.connection = NWConnection(to: endpoint, using: .gemini)
if #available(iOS 15.0, *) {
connection.parameters.attribution = attribution
}
self.connection.stateUpdateHandler = { (newState) in
switch newState {
case .ready:
@ -65,6 +63,13 @@ public class GeminiDataTask {
public func resume() {
guard state == .unstarted else { return }
#if os(iOS)
if #available(iOS 15.0, *) {
connection.parameters.attribution = attribution
}
#endif
state = .started
connection.start(queue: GeminiDataTask.queue)
}