sentry-cocoa icon indicating copy to clipboard operation
sentry-cocoa copied to clipboard

Remove deprecated SCNetworkReachability

Open noahsmartin opened this issue 6 months ago • 0 comments

Problem Statement

While poking around the codebase a bit to understand the networking side, I noticed use of SCNetworkReachability, which is deprecated with a detailed message from Apple in their docs:

All SCNetworkReachability functions are deprecated, because network conditions change too frequently for preflight reachability tests to be accurate and useful. Instead of trying to perform a preflight check, just attempt your connection. The connection may not be available immediately, but you can use [waitsForConnectivity](https://developer.apple.com/documentation/Foundation/URLSessionConfiguration/waitsForConnectivity) in your [URLSessionConfiguration](https://developer.apple.com/documentation/Foundation/URLSessionConfiguration) to automatically connect as soon as it’s possible to do so. If you’re using the [Network](https://developer.apple.com/documentation/Network) framework, you can monitor the state of an [NWConnection](https://developer.apple.com/documentation/Network/NWConnection) ([nw_connection_t](https://developer.apple.com/documentation/Network/nw_connection_t) in Objective-C), which lets you know when the connection is waiting for a change in connectivity before automatically proceeding. In limited cases, if you need to change a network request based on the network you’re using, use [NWPathMonitor](https://developer.apple.com/documentation/Network/NWPathMonitor) to observe the system networking state.

Solution Brainstorm

It would be nice if we didn't need reachability at all as Apple says in the docs, but I see it's used for re-sending failed requests when a connection is made, which makes sense to me. So I think we should switch it to NWPathMonitor. I've used this API before and it should be pretty straightforward, and it would support all platforms so we won't need SENTRY_HAS_REACHABILITY. Only catch is it supports iOS 12+. We technically still support iOS 11 but Xcode does not support iOS 11 anymore, so we might be able to just easily drop iOS 11 without a major SDK version increase.

Are you willing to submit a PR?

No response

noahsmartin avatar Jun 20 '25 15:06 noahsmartin