@@ -103,37 +103,6 @@ virtual NetworkCost GetNetworkCost()
103103
104104 void NetworkInformation::SetupNetDetect ()
105105 {
106- auto weak_this = std::weak_ptr<NetworkInformation>(shared_from_this ());
107-
108- m_reach = [ODWReachability reachabilityForInternetConnection ];
109- void (^block)(NSNotification *) = ^(NSNotification *)
110- {
111- auto strong_this = weak_this.lock ();
112- if (!strong_this)
113- {
114- return ;
115- }
116-
117- // NetworkCost information is not available until iOS 12.
118- // Just make the best guess here.
119- switch (m_reach.currentReachabilityStatus )
120- {
121- case NotReachable:
122- strong_this->UpdateType (NetworkType_Unknown);
123- strong_this->UpdateCost (NetworkCost_Unknown);
124- break ;
125- case ReachableViaWiFi:
126- strong_this->UpdateType (NetworkType_Wifi);
127- strong_this->UpdateCost (NetworkCost_Unmetered);
128- break ;
129- case ReachableViaWWAN:
130- strong_this->UpdateType (NetworkType_WWAN);
131- strong_this->UpdateCost (NetworkCost_Metered);
132- break ;
133- }
134- };
135- block (nil ); // Update the initial status.
136-
137106 if (@available (macOS 10.14 , iOS 12.0 , *))
138107 {
139108 m_monitor = nw_path_monitor_create ();
@@ -186,15 +155,49 @@ virtual NetworkCost GetNetworkCost()
186155 nw_path_monitor_cancel (m_monitor);
187156 }
188157 }
189- else if (m_isNetDetectEnabled)
158+ else
190159 {
191- m_notificationId =
192- [[NSNotificationCenter defaultCenter ]
193- addObserverForName: kNetworkReachabilityChangedNotification
194- object: nil
195- queue: nil
196- usingBlock: block];
197- [m_reach startNotifier ];
160+ auto weak_this = std::weak_ptr<NetworkInformation>(shared_from_this ());
161+
162+ m_reach = [ODWReachability reachabilityForInternetConnection ];
163+ void (^block)(NSNotification *) = ^(NSNotification *)
164+ {
165+ auto strong_this = weak_this.lock ();
166+ if (!strong_this)
167+ {
168+ return ;
169+ }
170+
171+ // NetworkCost information is not available until iOS 12.
172+ // Just make the best guess here.
173+ switch (m_reach.currentReachabilityStatus )
174+ {
175+ case NotReachable:
176+ strong_this->UpdateType (NetworkType_Unknown);
177+ strong_this->UpdateCost (NetworkCost_Unknown);
178+ break ;
179+ case ReachableViaWiFi:
180+ strong_this->UpdateType (NetworkType_Wifi);
181+ strong_this->UpdateCost (NetworkCost_Unmetered);
182+ break ;
183+ case ReachableViaWWAN:
184+ strong_this->UpdateType (NetworkType_WWAN);
185+ strong_this->UpdateCost (NetworkCost_Metered);
186+ break ;
187+ }
188+ };
189+ block (nil ); // Update the initial status.
190+
191+ if (m_isNetDetectEnabled)
192+ {
193+ m_notificationId =
194+ [[NSNotificationCenter defaultCenter ]
195+ addObserverForName: kNetworkReachabilityChangedNotification
196+ object: nil
197+ queue: nil
198+ usingBlock: block];
199+ [m_reach startNotifier ];
200+ }
198201 }
199202 }
200203
0 commit comments