From 686153da7b708ab9d552c99aebb1af4d5bb1bf95 Mon Sep 17 00:00:00 2001 From: Tommy Meisel Date: Mon, 5 Jan 2026 13:50:20 -0800 Subject: [PATCH 1/2] wrap all m_reach in the iOS 12+ else block --- lib/pal/posix/NetworkInformationImpl.mm | 62 ++++++++++++------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/lib/pal/posix/NetworkInformationImpl.mm b/lib/pal/posix/NetworkInformationImpl.mm index d7ba15403..c70b301ed 100644 --- a/lib/pal/posix/NetworkInformationImpl.mm +++ b/lib/pal/posix/NetworkInformationImpl.mm @@ -103,37 +103,6 @@ virtual NetworkCost GetNetworkCost() void NetworkInformation::SetupNetDetect() { - auto weak_this = std::weak_ptr(shared_from_this()); - - m_reach = [ODWReachability reachabilityForInternetConnection]; - void (^block)(NSNotification*) = ^(NSNotification*) - { - auto strong_this = weak_this.lock(); - if (!strong_this) - { - return; - } - - // NetworkCost information is not available until iOS 12. - // Just make the best guess here. - switch (m_reach.currentReachabilityStatus) - { - case NotReachable: - strong_this->UpdateType(NetworkType_Unknown); - strong_this->UpdateCost(NetworkCost_Unknown); - break; - case ReachableViaWiFi: - strong_this->UpdateType(NetworkType_Wifi); - strong_this->UpdateCost(NetworkCost_Unmetered); - break; - case ReachableViaWWAN: - strong_this->UpdateType(NetworkType_WWAN); - strong_this->UpdateCost(NetworkCost_Metered); - break; - } - }; - block(nil); // Update the initial status. - if (@available(macOS 10.14, iOS 12.0, *)) { m_monitor = nw_path_monitor_create(); @@ -188,6 +157,37 @@ virtual NetworkCost GetNetworkCost() } else if (m_isNetDetectEnabled) { + auto weak_this = std::weak_ptr(shared_from_this()); + + m_reach = [ODWReachability reachabilityForInternetConnection]; + void (^block)(NSNotification*) = ^(NSNotification*) + { + auto strong_this = weak_this.lock(); + if (!strong_this) + { + return; + } + + // NetworkCost information is not available until iOS 12. + // Just make the best guess here. + switch (m_reach.currentReachabilityStatus) + { + case NotReachable: + strong_this->UpdateType(NetworkType_Unknown); + strong_this->UpdateCost(NetworkCost_Unknown); + break; + case ReachableViaWiFi: + strong_this->UpdateType(NetworkType_Wifi); + strong_this->UpdateCost(NetworkCost_Unmetered); + break; + case ReachableViaWWAN: + strong_this->UpdateType(NetworkType_WWAN); + strong_this->UpdateCost(NetworkCost_Metered); + break; + } + }; + block(nil); // Update the initial status. + m_notificationId = [[NSNotificationCenter defaultCenter] addObserverForName: kNetworkReachabilityChangedNotification From 7a8beb8f516714faf9a04a2e7bc7f6d38731f3ac Mon Sep 17 00:00:00 2001 From: Tommy Meisel Date: Mon, 5 Jan 2026 14:02:16 -0800 Subject: [PATCH 2/2] update initial status even if net detect is disabled --- lib/pal/posix/NetworkInformationImpl.mm | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/pal/posix/NetworkInformationImpl.mm b/lib/pal/posix/NetworkInformationImpl.mm index c70b301ed..67713d67d 100644 --- a/lib/pal/posix/NetworkInformationImpl.mm +++ b/lib/pal/posix/NetworkInformationImpl.mm @@ -155,7 +155,7 @@ virtual NetworkCost GetNetworkCost() nw_path_monitor_cancel(m_monitor); } } - else if (m_isNetDetectEnabled) + else { auto weak_this = std::weak_ptr(shared_from_this()); @@ -188,13 +188,16 @@ virtual NetworkCost GetNetworkCost() }; block(nil); // Update the initial status. - m_notificationId = - [[NSNotificationCenter defaultCenter] - addObserverForName: kNetworkReachabilityChangedNotification - object: nil - queue: nil - usingBlock: block]; - [m_reach startNotifier]; + if (m_isNetDetectEnabled) + { + m_notificationId = + [[NSNotificationCenter defaultCenter] + addObserverForName: kNetworkReachabilityChangedNotification + object: nil + queue: nil + usingBlock: block]; + [m_reach startNotifier]; + } } }