Ver Fonte

Deprecate `NetworkReachabilityManager` (#3947)

### Issue Link :link:
Fixes #3943

### Goals :soccer:
Apple's `SCNetworkReachability` types were deprecated in iOS 17.4
related OS versions. This PR deprecates `NetworkReachabilityManager` in
favor of `NWPathMonitor` from Network.framework, which has been the
better solution for many years now.

This PR also updates various infrastructure bits, and deletes the
`.swiftpm` directory to prevent Xcode from generating schemes when
integrating the package.

### Implementation Details :construction:
Class deprecated.

### Testing Details :mag:
Tests deprecated.
Jon Shier há 1 mês atrás
pai
commit
d8428b9772

+ 2 - 0
.gitignore

@@ -40,3 +40,5 @@ Carthage/Build
 .UlyssesRoot
 .Ulysses-Settings.plist
 .Ulysses-Group.plist
+
+.swiftpm/

+ 1 - 1
Alamofire.xcodeproj/project.pbxproj

@@ -1438,7 +1438,7 @@
 			attributes = {
 				BuildIndependentTargetsInParallel = YES;
 				LastSwiftUpdateCheck = 1500;
-				LastUpgradeCheck = 1640;
+				LastUpgradeCheck = 2610;
 				ORGANIZATIONNAME = Alamofire;
 				TargetAttributes = {
 					31293064263E17D600473CEA = {

+ 1 - 1
Alamofire.xcodeproj/xcshareddata/xcschemes/Alamofire iOS.xcscheme

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <Scheme
-   LastUpgradeVersion = "1640"
+   LastUpgradeVersion = "2610"
    version = "1.7">
    <BuildAction
       parallelizeBuildables = "YES"

+ 1 - 1
Alamofire.xcodeproj/xcshareddata/xcschemes/Alamofire macOS.xcscheme

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <Scheme
-   LastUpgradeVersion = "1640"
+   LastUpgradeVersion = "2610"
    version = "1.7">
    <BuildAction
       parallelizeBuildables = "YES"

+ 1 - 1
Alamofire.xcodeproj/xcshareddata/xcschemes/Alamofire tvOS.xcscheme

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <Scheme
-   LastUpgradeVersion = "1640"
+   LastUpgradeVersion = "2610"
    version = "1.7">
    <BuildAction
       parallelizeBuildables = "YES"

+ 1 - 1
Alamofire.xcodeproj/xcshareddata/xcschemes/Alamofire visionOS.xcscheme

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <Scheme
-   LastUpgradeVersion = "1640"
+   LastUpgradeVersion = "2610"
    version = "1.7">
    <BuildAction
       parallelizeBuildables = "YES"

+ 1 - 1
Alamofire.xcodeproj/xcshareddata/xcschemes/Alamofire watchOS.xcscheme

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <Scheme
-   LastUpgradeVersion = "1640"
+   LastUpgradeVersion = "2610"
    version = "1.7">
    <BuildAction
       parallelizeBuildables = "YES"

+ 1 - 1
Example/iOS Example.xcodeproj/xcshareddata/xcschemes/iOS Example.xcscheme

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <Scheme
-   LastUpgradeVersion = "1640"
+   LastUpgradeVersion = "2610"
    version = "1.3">
    <BuildAction
       parallelizeBuildables = "YES"

+ 2 - 2
Source/Alamofire.swift

@@ -29,8 +29,8 @@ import Foundation
 #endif
 
 // Enforce minimum Swift version for all platforms and build systems.
-#if swift(<5.9.0)
-#error("Alamofire doesn't support Swift versions below 5.9.")
+#if compiler(<6.0)
+#error("Alamofire doesn't support Swift compiler versions below 6.0.")
 #endif
 
 /// Reference to `Session.default` for quick bootstrapping and examples.

+ 3 - 1
Source/Core/HTTPHeaders.swift

@@ -406,7 +406,7 @@ extension HTTPHeader {
                 #else
                 return "macOS"
                 #endif
-                #elseif swift(>=5.9.2) && os(visionOS)
+                #elseif os(visionOS)
                 return "visionOS"
                 #elseif os(Linux)
                 return "Linux"
@@ -414,6 +414,8 @@ extension HTTPHeader {
                 return "Windows"
                 #elseif os(Android)
                 return "Android"
+                #elseif os(WASI)
+                return "WASI"
                 #else
                 return "Unknown"
                 #endif

+ 1 - 6
Source/Core/Protected.swift

@@ -90,11 +90,8 @@ final class Protected<Value> {
     #else
     #error("This platform needs a Lock-conforming type without Foundation.")
     #endif
-    #if compiler(>=6)
+
     private nonisolated(unsafe) var value: Value
-    #else
-    private var value: Value
-    #endif
 
     init(_ value: Value) {
         self.value = value
@@ -138,8 +135,6 @@ final class Protected<Value> {
 
 #if compiler(>=6)
 extension Protected: Sendable {}
-#else
-extension Protected: @unchecked Sendable {}
 #endif
 
 extension Protected where Value == Request.MutableState {

+ 2 - 2
Source/Core/WebSocketRequest.swift

@@ -526,9 +526,9 @@ extension WebSocketMessageSerializer {
 
 @available(macOS 10.15, iOS 13, tvOS 13, watchOS 6, *)
 struct PassthroughWebSocketMessageDecoder: WebSocketMessageSerializer {
-    public typealias Failure = Never
+    typealias Failure = Never
 
-    public func decode(_ message: URLSessionWebSocketTask.Message) -> URLSessionWebSocketTask.Message {
+    func decode(_ message: URLSessionWebSocketTask.Message) -> URLSessionWebSocketTask.Message {
         message
     }
 }

+ 7 - 4
Source/Features/NetworkReachabilityManager.swift

@@ -33,9 +33,14 @@ import SystemConfiguration
 /// Reachability can be used to determine background information about why a network operation failed, or to retry
 /// network requests when a connection is established. It should not be used to prevent a user from initiating a network
 /// request, as it's possible that an initial request may be required to establish reachability.
+@available(macOS, deprecated: 14.4, message: "Use NWPathMonitor instead.")
+@available(iOS, deprecated: 17.4, message: "Use NWPathMonitor instead.")
+@available(watchOS, deprecated: 9.4, message: "Use NWPathMonitor instead.")
+@available(tvOS, deprecated: 17.4, message: "Use NWPathMonitor instead.")
+@available(visionOS, deprecated: 1.4, message: "Use NWPathMonitor instead.")
 open class NetworkReachabilityManager: @unchecked Sendable {
     /// Defines the various states of network reachability.
-    public enum NetworkReachabilityStatus: Sendable {
+    public enum NetworkReachabilityStatus: Equatable, Sendable {
         /// It is unknown whether the network is reachable.
         case unknown
         /// The network is not reachable.
@@ -258,8 +263,6 @@ open class NetworkReachabilityManager: @unchecked Sendable {
 
 // MARK: -
 
-extension NetworkReachabilityManager.NetworkReachabilityStatus: Equatable {}
-
 extension SCNetworkReachabilityFlags {
     var isReachable: Bool { contains(.reachable) }
     var isConnectionRequired: Bool { contains(.connectionRequired) }
@@ -267,7 +270,7 @@ extension SCNetworkReachabilityFlags {
     var canConnectWithoutUserInteraction: Bool { canConnectAutomatically && !contains(.interventionRequired) }
     var isActuallyReachable: Bool { isReachable && (!isConnectionRequired || canConnectWithoutUserInteraction) }
     var isCellular: Bool {
-        #if os(iOS) || os(tvOS) || (swift(>=5.9) && os(visionOS))
+        #if os(iOS) || os(tvOS) || os(visionOS)
         return contains(.isWWAN)
         #else
         return false

+ 1 - 1
Source/Features/URLEncodedFormEncoder.swift

@@ -577,7 +577,7 @@ enum URLEncodedFormComponent {
     /// - parameters:
     ///     - value: Value of `Self` to set at the supplied path.
     ///     - path: `CodingKey` path to update with the supplied value.
-    public mutating func set(to value: URLEncodedFormComponent, at path: [any CodingKey]) {
+    mutating func set(to value: URLEncodedFormComponent, at path: [any CodingKey]) {
         set(&self, to: value, at: path)
     }
 

+ 5 - 0
Tests/NetworkReachabilityManagerTests.swift

@@ -29,6 +29,11 @@ import Foundation
 import SystemConfiguration
 import XCTest
 
+@available(macOS, deprecated: 14.4)
+@available(iOS, deprecated: 17.4)
+@available(watchOS, deprecated: 9.4)
+@available(tvOS, deprecated: 17.4)
+@available(visionOS, deprecated: 1.4)
 final class NetworkReachabilityManagerTestCase: BaseTestCase {
     // MARK: - Tests - Initialization
 

+ 3 - 1
Tests/SessionTests.swift

@@ -366,7 +366,7 @@ final class SessionTestCase: BaseTestCase {
                 #else
                 return "macOS"
                 #endif
-                #elseif swift(>=5.9.2) && os(visionOS)
+                #elseif os(visionOS)
                 return "visionOS"
                 #elseif os(Linux)
                 return "Linux"
@@ -374,6 +374,8 @@ final class SessionTestCase: BaseTestCase {
                 return "Windows"
                 #elseif os(Android)
                 return "Android"
+                #elseif os(WASI)
+                return "WASI"
                 #else
                 return "Unknown"
                 #endif

+ 13 - 13
Tests/TestHelpers.swift

@@ -361,12 +361,12 @@ extension Session {
                 requestModifier: requestModifier)
     }
 
-    func request<Parameters: Encodable>(_ endpoint: Endpoint,
-                                        parameters: Parameters? = nil,
-                                        encoder: any ParameterEncoder = URLEncodedFormParameterEncoder.default,
-                                        headers: HTTPHeaders? = nil,
-                                        interceptor: (any RequestInterceptor)? = nil,
-                                        requestModifier: RequestModifier? = nil) -> DataRequest {
+    func request<Parameters: Encodable & Sendable>(_ endpoint: Endpoint,
+                                                   parameters: Parameters? = nil,
+                                                   encoder: any ParameterEncoder = URLEncodedFormParameterEncoder.default,
+                                                   headers: HTTPHeaders? = nil,
+                                                   interceptor: (any RequestInterceptor)? = nil,
+                                                   requestModifier: RequestModifier? = nil) -> DataRequest {
         request(endpoint as (any URLConvertible),
                 method: endpoint.method,
                 parameters: parameters,
@@ -401,13 +401,13 @@ extension Session {
                       interceptor: interceptor)
     }
 
-    func download<Parameters: Encodable>(_ endpoint: Endpoint,
-                                         parameters: Parameters? = nil,
-                                         encoder: any ParameterEncoder = URLEncodedFormParameterEncoder.default,
-                                         headers: HTTPHeaders? = nil,
-                                         interceptor: (any RequestInterceptor)? = nil,
-                                         requestModifier: RequestModifier? = nil,
-                                         to destination: DownloadRequest.Destination? = nil) -> DownloadRequest {
+    func download<Parameters: Encodable & Sendable>(_ endpoint: Endpoint,
+                                                    parameters: Parameters? = nil,
+                                                    encoder: any ParameterEncoder = URLEncodedFormParameterEncoder.default,
+                                                    headers: HTTPHeaders? = nil,
+                                                    interceptor: (any RequestInterceptor)? = nil,
+                                                    requestModifier: RequestModifier? = nil,
+                                                    to destination: DownloadRequest.Destination? = nil) -> DownloadRequest {
         download(endpoint as (any URLConvertible),
                  method: endpoint.method,
                  parameters: parameters,

+ 1 - 1
watchOS Example/watchOS Example.xcodeproj/xcshareddata/xcschemes/watchOS Example WatchKit App.xcscheme

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <Scheme
-   LastUpgradeVersion = "1640"
+   LastUpgradeVersion = "2610"
    version = "1.3">
    <BuildAction
       parallelizeBuildables = "YES"