Reachability.swift: [4.2] Reachability()?.connection returns .none right after been initialized

Created on 30 Aug 2018  ·  6Comments  ·  Source: ashleymills/Reachability.swift

In 4.1, the following code Reachability().connection would provide .wifi or .cellular.
Since 4.2, Reachability().connection returns .none right after the initialization.

After a while, if subscribing to the notifications, the value returns to the real reachability state.
Is this the designed behavior or is this a regression ?

Regards

Most helpful comment

OK, I see the problem. I'll push a fix later today.

All 6 comments

@Drusy That looks like a regression. Thanks for reporting, I'll take a look

Cheers
Ash

In the sample iOS app in the repo, I tried printing connection immediately after calling startNotifier() - and it's showing the correct value (on device and simulator). Can you give me any more details?

try reachability?.startNotifier()
print(reachability!.connection)
// WiFi

@ashleymills my sample is as simple as this

let reachability = Reachability()
print(reachability!.connection)
// No Connection

I am not calling startNotifier() because in that case I do not need the notifications. I may misuse your API, but the behavior is definitely changing between 4.1 and 4.2

OK, I see the problem. I'll push a fix later today.

@ashleymills I'm still experiencing this issue with version 4.2.1 when building my project with Xcode 10 final release and iOS 12 SDK.

The scenario is the following one:

  1. Run the app without network connection (e.g. turn on airpline mode).
  2. Reachability returns there is no valid connection (.none) -as expected-.
  3. Turn off airpline mode or connect a working network connection.
  4. Reachability still returns .none as current connection. There is no change even after an hour without killing the app and running it again once a valid network connection is ready, which works fine.

I was also observing the following message in console output: "[NetworkInfo] Descriptors query returned error: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named com.apple.commcenter.coretelephony.xpc was invalidated." UserInfo={NSDebugDescription=The connection to service named com.apple.commcenter.coretelephony.xpc was invalidated.}"

In order to fix the issue, I had to manually add CoreTelephony as a required dependency. Everything works as expected now, both on iOS 12 and older versions when building the app with the final version of Xcode 10 and using Swift 4.2. The message still appears on iOS simulator (and does not work, obviously) but it does not on a real device.

I'd suggest you either to update README.md file to add this information or update podspec file to add CoreTelephony as a subspec/dependency.

Was this page helpful?
0 / 5 - 0 ratings