Skip to content

Commit 7d634cd

Browse files
authored
Support linking with lower version OS (altstoreio#5)
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.
1 parent e72c8e0 commit 7d634cd

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import PackageDescription
66
let package = Package(
77
name: "AltKit",
88
platforms: [
9-
.iOS(.v12),
10-
.tvOS(.v12)
9+
.iOS(.v11),
10+
.tvOS(.v11)
1111
],
1212
products: [
1313
// Products define the executables and libraries a package produces, and make them visible to other packages.

Sources/AltKit/Server/NetworkConnection.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import Foundation
1010
import Network
1111

12+
@available(iOS 12, tvOS 12, watchOS 5, macOS 10.14, *)
1213
public class NetworkConnection: NSObject, Connection
1314
{
1415
public let nwConnection: NWConnection
@@ -52,10 +53,7 @@ public class NetworkConnection: NSObject, Connection
5253
default: self.nwConnection.cancel()
5354
}
5455
}
55-
}
56-
57-
extension NetworkConnection
58-
{
56+
5957
override public var description: String {
6058
return "\(self.nwConnection.endpoint) (Network)"
6159
}

Sources/AltKit/Server/ServerManager.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public enum ConnectionError: LocalizedError
1919
case connectionFailed(Server)
2020
case connectionDropped(Server)
2121
case unknownUDID
22+
case unsupportedOS
2223

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

108110
self.dispatchQueue.async {
109-
111+
guard #available(iOS 12, tvOS 12, watchOS 5, macOS 10.14, *) else {
112+
finish(.failure(ConnectionError.unsupportedOS))
113+
return
114+
}
110115
print("Connecting to service:", server.service)
111116

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

0 commit comments

Comments
 (0)