Bug 28713 - SystemConfiguration.Reachability notification flags = 0 on turning wifi back on
Summary: SystemConfiguration.Reachability notification flags = 0 on turning wifi back on
Status: RESOLVED ANSWERED
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Library (Xamarin.Mac.dll) ()
Version: 1.12.0
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: master
Assignee: Chris Hamons
URL:
Depends on:
Blocks:
 
Reported: 2015-04-02 18:26 UTC by Radu
Modified: 2017-01-20 19:09 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description Radu 2015-04-02 18:26:35 UTC
all I wanted to do is to be notified when internet connection becomes available

var reachability = new NetworkReachability ("www.google.com");			
reachability.SetNotification(flags => {... my code...});
reachability.Schedule();

When the reachability is first scheduled, the callback is triggered with flag Reachable. If I turn off wifi, it is triggered with flag ConnectionRequired|Reachable|TransientConnection. When I turn wi fi back on, it is triggered with flag = 0. Is this flag normal? I was expecting something to suggest the target is reachable

I did one more step: when getting the 0 flag, I retested, in the callback method, to see if the target is reachable using a new Reachability object and the TryGetFlag method. The flag obtained this way is also 0, and the TryGetFlag method returned true. I can't seem to be able to obtain what I want. I think interpreting flag = 0 as Reachable is dangerous
Comment 1 Radu 2015-04-03 03:57:30 UTC
I noticed that sometimes, after the wifi connection is reestablished, and after I get the notification trigered with flags =0, after some time the notification is triggered again with flags = Reachable. But this can take even 10-15 minutes
Comment 2 Radu 2015-04-03 05:36:04 UTC
I noticed that even with the TryGetFlags method, it also can take up to 15 minutes after turning wifi back on, to get a Rechable flag. In this period TryGetMethod returns true, flag = 0 and google.com loads with no problems in safari... this is unreliable.
Comment 3 Chris Hamons 2015-04-08 13:56:20 UTC
Could you post a full sample showing the problem?

We should test this against the obj-c API to see if Apple is showing that behavior (not our bug then) or if we're changing something in the binding layer.
Comment 4 Radu 2015-07-30 03:55:10 UTC
it's been 5 months since then...
but this is a known issue in Xamarin. You can even find blogs about this:
https://thomasbandt.com/how-to-check-network-reachability-with-xamarinios-on-ios-8
"The bad thing is: That doesn't seem to work properly on iOS 8.3 anymore, so I had to do some investigation"

The workaround seems to suggest that there should be only one networkreachability in the app and this must work using the setNotification callback and update some static variable when that happens. I can confirm that the solution in this article did solve the issues and managed to provide a reliable behavior for checking internet connection.
Comment 5 Timothy Risi 2017-01-20 19:09:07 UTC
I'm glad you found a way to get it working.

If you run into any more issues, feel free to re-open the bug.