Skip to content

Commit

Permalink
Support linking with lower version OS (#5)
Browse files Browse the repository at this point in the history
Swift PM does not have a good way to conditionally include a package. That
means that apps targeting a lower OS version cannot import AltKit. As a
workaround, we lower the linking version while inserting availability
checks into AltKit.

Since NWConnection requires iOS 12, we will return an error when trying to
connect with iOS 11.
  • Loading branch information
osy committed Nov 8, 2021
1 parent e72c8e0 commit 7d634cd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import PackageDescription
let package = Package(
name: "AltKit",
platforms: [
.iOS(.v12),
.tvOS(.v12)
.iOS(.v11),
.tvOS(.v11)
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
Expand Down
6 changes: 2 additions & 4 deletions Sources/AltKit/Server/NetworkConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import Foundation
import Network

@available(iOS 12, tvOS 12, watchOS 5, macOS 10.14, *)
public class NetworkConnection: NSObject, Connection
{
public let nwConnection: NWConnection
Expand Down Expand Up @@ -52,10 +53,7 @@ public class NetworkConnection: NSObject, Connection
default: self.nwConnection.cancel()
}
}
}

extension NetworkConnection
{

override public var description: String {
return "\(self.nwConnection.endpoint) (Network)"
}
Expand Down
7 changes: 6 additions & 1 deletion Sources/AltKit/Server/ServerManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public enum ConnectionError: LocalizedError
case connectionFailed(Server)
case connectionDropped(Server)
case unknownUDID
case unsupportedOS

public var errorDescription: String? {
switch self
Expand All @@ -27,6 +28,7 @@ public enum ConnectionError: LocalizedError
case .connectionFailed: return NSLocalizedString("Could not connect to AltServer.", comment: "")
case .connectionDropped: return NSLocalizedString("The connection to AltServer was dropped.", comment: "")
case .unknownUDID: return NSLocalizedString("This device's UDID could not be determined.", comment: "")
case .unsupportedOS: return NSLocalizedString("This device's OS version is too old to run AltKit.", comment: "")
}
}
}
Expand Down Expand Up @@ -106,7 +108,10 @@ public extension ServerManager
}

self.dispatchQueue.async {

guard #available(iOS 12, tvOS 12, watchOS 5, macOS 10.14, *) else {
finish(.failure(ConnectionError.unsupportedOS))
return
}
print("Connecting to service:", server.service)

let connection = NWConnection(to: .service(name: server.service.name, type: server.service.type, domain: server.service.domain, interface: nil), using: .tcp)
Expand Down

0 comments on commit 7d634cd

Please sign in to comment.