1

Expected NWPathMonitor's pathUpdateHandler will get called only when there is a change in the network activity (e.g., cellular->wifi or wifi1->wifi2 or wifi->no network etc...).

What I am observing is 'pathUpdateHandler' block gets called even when the app in the background for say 30secs and comes to foreground. This isn't expected. Also when network changes 'pathUpdateHandler' block gets invoked multiple times.

Is this expected behaviour? Or is there a workaround for this kind of behaviour? My device is iOS 13.7 Here is my code snippet

-(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);
}
Shiva Reddy
  • 456
  • 1
  • 7
  • 26
  • What status updates are you getting? For what interfaces? Have you considered excluding updates for interface types you aren't interested in. – Paulw11 Sep 28 '20 at 22:38
  • @Paulw11, Problem1: Multiple status updates with status: 'nw_path_status_satisfied' and interface: 'nw_interface_type_wifi' when ever I swiftch from No WifFi -> WifFi Problem2: If I put the app in the background for say 30seconds and bring it back without doing anything (No change to Network) then getting multiple 'pathUpdate' callbacks for same interface type with same status as in problem 1. – Shiva Reddy Sep 29 '20 at 03:08

0 Answers0