@@ -84,7 +84,7 @@ virtual NetworkCost GetNetworkCost()
84
84
85
85
NetworkInformation::~NetworkInformation () noexcept
86
86
{
87
- if (@available (iOS 12.0 , *))
87
+ if (@available (macOS 10.14 , iOS 12.0 , *))
88
88
{
89
89
if (m_isNetDetectEnabled)
90
90
{
@@ -105,7 +105,36 @@ virtual NetworkCost GetNetworkCost()
105
105
{
106
106
auto weak_this = std::weak_ptr<NetworkInformation>(shared_from_this ());
107
107
108
- if (@available (iOS 12.0 , *))
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
+
137
+ if (@available (macOS 10.14 , iOS 12.0 , *))
109
138
{
110
139
m_monitor = nw_path_monitor_create ();
111
140
nw_path_monitor_set_queue (m_monitor, dispatch_get_global_queue (QOS_CLASS_BACKGROUND , 0 ));
@@ -136,7 +165,7 @@ virtual NetworkCost GetNetworkCost()
136
165
type = NetworkType_Wired;
137
166
}
138
167
cost = nw_path_is_expensive (path) ? NetworkCost_Metered : NetworkCost_Unmetered;
139
- if (@available (iOS 13.0 , *))
168
+ if (@available (macOS 10.15 , iOS 13.0 , *))
140
169
{
141
170
if (nw_path_is_constrained (path))
142
171
{
@@ -157,46 +186,15 @@ virtual NetworkCost GetNetworkCost()
157
186
nw_path_monitor_cancel (m_monitor);
158
187
}
159
188
}
160
- else
189
+ else if (m_isNetDetectEnabled)
161
190
{
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
- if (m_isNetDetectEnabled)
191
- {
192
- m_notificationId =
193
- [[NSNotificationCenter defaultCenter ]
194
- addObserverForName: kNetworkReachabilityChangedNotification
195
- object: nil
196
- queue: nil
197
- usingBlock: block];
198
- [m_reach startNotifier ];
199
- }
191
+ m_notificationId =
192
+ [[NSNotificationCenter defaultCenter ]
193
+ addObserverForName: kNetworkReachabilityChangedNotification
194
+ object: nil
195
+ queue: nil
196
+ usingBlock: block];
197
+ [m_reach startNotifier ];
200
198
}
201
199
}
202
200
0 commit comments