|
|
@@ -51,7 +51,7 @@ func callback(reachability:SCNetworkReachability, flags: SCNetworkReachabilityFl
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-public class Reachability: NSObject {
|
|
|
+public class Reachability {
|
|
|
|
|
|
public typealias NetworkReachable = (Reachability) -> ()
|
|
|
public typealias NetworkUnreachable = (Reachability) -> ()
|
|
|
@@ -110,25 +110,14 @@ public class Reachability: NSObject {
|
|
|
self.reachabilityRef = reachabilityRef
|
|
|
}
|
|
|
|
|
|
- deinit {
|
|
|
- stopNotifier()
|
|
|
-
|
|
|
- reachabilityRef = nil
|
|
|
- whenReachable = nil
|
|
|
- whenUnreachable = nil
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-public extension Reachability {
|
|
|
-
|
|
|
- convenience init(hostname: String) throws {
|
|
|
+ public convenience init?(hostname: String) {
|
|
|
|
|
|
- guard let ref = SCNetworkReachabilityCreateWithName(nil, hostname) else { throw ReachabilityError.FailedToCreateWithHostname(hostname) }
|
|
|
+ guard let ref = SCNetworkReachabilityCreateWithName(nil, hostname) else { return nil }
|
|
|
|
|
|
self.init(reachabilityRef: ref)
|
|
|
}
|
|
|
|
|
|
- class func reachabilityForInternetConnection() throws -> Reachability {
|
|
|
+ public convenience init?() {
|
|
|
|
|
|
var zeroAddress = sockaddr_in()
|
|
|
zeroAddress.sin_len = UInt8(sizeofValue(zeroAddress))
|
|
|
@@ -136,11 +125,22 @@ public extension Reachability {
|
|
|
|
|
|
guard let ref = withUnsafePointer(&zeroAddress, {
|
|
|
SCNetworkReachabilityCreateWithAddress(nil, UnsafePointer($0))
|
|
|
- }) else { throw ReachabilityError.FailedToCreateWithAddress(zeroAddress) }
|
|
|
+ }) else { return nil }
|
|
|
|
|
|
- return Reachability(reachabilityRef: ref)
|
|
|
+ self.init(reachabilityRef: ref)
|
|
|
}
|
|
|
|
|
|
+ deinit {
|
|
|
+ stopNotifier()
|
|
|
+
|
|
|
+ reachabilityRef = nil
|
|
|
+ whenReachable = nil
|
|
|
+ whenUnreachable = nil
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+public extension Reachability {
|
|
|
+
|
|
|
// MARK: - *** Notifier methods ***
|
|
|
func startNotifier() throws {
|
|
|
|
|
|
@@ -211,7 +211,7 @@ public extension Reachability {
|
|
|
return !isOnWWANFlagSet
|
|
|
}
|
|
|
|
|
|
- override var description: String {
|
|
|
+ var description: String {
|
|
|
|
|
|
let W = isRunningOnDevice ? (isOnWWANFlagSet ? "W" : "-") : "X"
|
|
|
let R = isReachableFlagSet ? "R" : "-"
|