Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.2] Reachability()?.connection returns .none right after been initialized #307

Closed
Drusy opened this issue Aug 30, 2018 · 6 comments
Closed

Comments

@Drusy
Copy link

Drusy commented Aug 30, 2018

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

@ashleymills
Copy link
Owner

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

Cheers
Ash

@ashleymills
Copy link
Owner

ashleymills commented Aug 30, 2018

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

@Drusy
Copy link
Author

Drusy commented Aug 30, 2018

@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

@ashleymills
Copy link
Owner

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

@ashleymills
Copy link
Owner

@corteggo
Copy link
Contributor

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants