我有这段代码来测试网络连接:
if (remoteHostReachability == null) {
remoteHostReachability = new NetworkReachability (HostName);
// Need to probe before we queue, or we wont get any meaningful values
// this only happens when you create NetworkReachability from a hostname
reachable = remoteHostReachability.TryGetFlags (out flags);
//remoteHostReachability.SetCallback (OnChange);
remoteHostReachability.SetNotification (OnChange);
remoteHostReachability.Schedule (CFRunLoop.Current, CFRunLoop.ModeDefault);
} else {
reachable = remoteHostReachability.TryGetFlags (out flags);
}
第一次调用它时,标志是可以的。但是,当第二次调用它时,标志总是等于零。在 iOS 模拟器 5.0 上测试。