问题描述
仅当网络活动发生变化(例如,蜂窝网络-> wifi或wifi1-> wifi2或wifi->无网络等...)时,才会调用预期的NWPathMonitor的pathUpdateHandler。
我正在观察的是“ pathUpdateHandler”块被调用,即使该应用在后台运行了30秒并进入前台。这是不期望的。 同样,当网络更改时,“ pathUpdateHandler”块也会被多次调用。
这是预期的行为吗?还是有针对这种行为的解决方法? 我的设备是iOS 13.7 这是我的代码段
-(void) startMonitor {
self.pathMonitor = nw_path_monitor_create();
nw_path_monitor_set_update_handler(self.pathMonitor,^(nw_path_t _Nonnull path) {
DDLogVerbose(@"Network path changed %d",nw_path_get_status(path));
if (nw_path_uses_interface_type(path,nw_interface_type_wifi)) {
DDLogVerbose(@"Network path user interface type WiFi");
} else if (nw_path_uses_interface_type(path,nw_interface_type_cellular)) {
DDLogVerbose(@"Network path user interface type Cellular");
} else if (nw_path_uses_interface_type(path,nw_interface_type_wired)) {
DDLogVerbose(@"Network path user interface type Wired");
} else if (nw_path_uses_interface_type(path,nw_interface_type_loopback)) {
DDLogVerbose(@"Network path user interface type Loopback");
} else if (nw_path_uses_interface_type(path,nw_interface_type_other)) {
DDLogVerbose(@"Network path user interface type Other");
}
});
nw_path_monitor_start(self.pathMonitor);
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)