Reachability.swift
Reachability.swift copied to clipboard
Closures not triggered
Xcode: Version 10.1 (10B61) iPhone 6s Plus 16gb - iOS 12.1.4 Manual install, i am using Reachability inside Cocoa Touch Framework
I tried this example of closures from the README:
//declare this property where it won't go out of scope relative to your listener
let reachability = Reachability()!
reachability.whenReachable = { reachability in
if reachability.connection == .wifi {
print("Reachable via WiFi")
} else {
print("Reachable via Cellular")
}
}
reachability.whenUnreachable = { _ in
print("Not reachable")
}
do {
try reachability.startNotifier()
} catch {
print("Unable to start notifier")
}
But no print or error shown in console.
However, then i tried this:
let reachability = Reachability()!
if reachability.connection != .none {
if reachability.connection == .wifi {
print("Via WiFi")
} else {
print("Via Cellular")
}
} else {
print("None")
}
the print statement is called, works fine for detecting network.
Any idea why?
inconsistent in reachability.
@winadiw / @vtkumaresan have you found a workaround for this issue?
I face the same issue
For me it's only in simulator