微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

NWPathMonitor的pathUpdateHandler块在应用程序后台调用到前台过渡

如何解决NWPathMonitor的pathUpdateHandler块在应用程序后台调用到前台过渡

仅当网络活动发生变化(例如,蜂窝网络-> 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 举报,一经查实,本站将立刻删除。