-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Replace deprecated NetworkReachability with NWPathMonitor on iOS/macOS #32354
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
base: main
Are you sure you want to change the base?
Replace deprecated NetworkReachability with NWPathMonitor on iOS/macOS #32354
Conversation
Co-authored-by: jfversluis <[email protected]>
Co-authored-by: jfversluis <[email protected]>
|
/azp run MAUI-public |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
NWPathMonitor is supported from iOS 12 and up so just replacing it should not mess with our bottom support platform |
src/Essentials/src/Connectivity/Connectivity.ios.tvos.macos.reachability.cs
Outdated
Show resolved
Hide resolved
src/Essentials/src/Connectivity/Connectivity.ios.tvos.macos.reachability.cs
Show resolved
Hide resolved
|
@copilot address comments, check if the suggestions make sense, if not, explain why |
…add path initialization comment Co-authored-by: jfversluis <[email protected]>
|
Azure Pipelines successfully started running 1 pipeline(s). |
Cheesebaron
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like there are two instances of NWPathMonitor set up. One in Reachability and another one in ReachabilityListener. I don't think it is necessary to have two.
There are no checks for reachability to a specific host name anymore so I thing the two classes Reachability and ReachabilityListener can be made into just one class.
As you also suggested yourself, CurrentPath on the monitor can return null until a first update is triggered on the NWPathMonitor. It seems like GetCurrentPath() implicitly starts the monitor, but the if statement in there does nothing.
| pathUpdateHandler = async (NWPath path) => | ||
| { | ||
| // Add in artificial delay so the connection status has time to change | ||
| await Task.Delay(ConnectionStatusChangeDelayMs); | ||
| ReachabilityChanged?.Invoke(); | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of creating a Action it would be ideal to have a method instead. It can be async void if needed here as there is an awaited Task.Delay
|
@copilot address comments |
All review comments have already been addressed in commit d63d96c:
Both comment threads are now resolved. The code builds successfully with no warnings. |
Replace obsolete NetworkReachability with NWPathMonitor for iOS/macOS 17.4+
Plan
Summary
This PR successfully replaces the obsolete
NetworkReachabilityAPI from SystemConfiguration framework with the modernNWPathMonitorAPI from the Network framework for iOS, tvOS, and macOS platforms.Recent Changes
Code Review Feedback Addressed:
SnapshotHandlerfrom event-like add/remove (+=/-=) to property assignment pattern (line 123)Changes Made
Files Modified (2 files changed, 71 insertions(+), 109 deletions(-))
src/Essentials/src/Connectivity/Connectivity.ios.tvos.macos.cssrc/Essentials/src/Connectivity/Connectivity.ios.tvos.macos.reachability.csSystemConfiguration.NetworkReachabilitywithNetwork.NWPathMonitorReachabilitystatic class to useNWPathMonitor.CurrentPathfor all network status checksReachabilityListenerclass to useNWPathMonitor.SnapshotHandlerproperty assignment (not event pattern)NetworkReachabilityFlagsNWPathMonitorinstance with thread-safe accessConnectionStatusChangeDelayMsper code review feedbackTechnical Details
Testing
Related Issues
Fixes the issue about NetworkReachability being obsolete on iOS/maccatalyst 17.4+ as reported in the issue screenshot showing CA1422 warnings.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.