Reachability.swift icon indicating copy to clipboard operation
Reachability.swift copied to clipboard

Closures not triggered

Open winadiw opened this issue 6 years ago • 4 comments

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?

winadiw avatar Mar 08 '19 17:03 winadiw

inconsistent in reachability.

vtkumaresan avatar Jun 15 '19 16:06 vtkumaresan

@winadiw / @vtkumaresan have you found a workaround for this issue?

bhorwood avatar Aug 07 '19 22:08 bhorwood

I face the same issue

richardhsieh18 avatar Dec 03 '19 02:12 richardhsieh18

For me it's only in simulator

Patrick-Remy avatar Feb 19 '20 16:02 Patrick-Remy