On iOS 13.1, CNCopyCurrentNetworkInfo occasionally doesn't work.

Altough we are using NEHotspotConfiguration API to configure the current Wi-Fi network, occasionally CNCopyCurrentNetworkInfo returns NULL. The only way to recover was rebooting the phone (I haven't tried resetting the network settings as was suggested else where). Regardless ,this sounds like a bug in the API and I was wondering if others see the same problem and/or if it's a known issue and is getting addressed.

Thanks!

Replies

Hi eskimo1,


This bug continutes to exist in 13.2.2 and severaly impacts our developer abilities to connect IoT devices to our app through IoT device pairing and onboarding. I've submitted an additional ticket to help raise priority, thank you for swift reponse and resolution.


Ticket: Nov 19, 2019 at 9:51 AM – FB7455848


Adam

I've submitted an additional ticket

Thanks for that, but I don’t see a sysdiagnose log attached to that bug report. Please review my 31 Oct and 15 Oct for suggestions on how to file bugs about this.

ps I edited your post to prevent my email address showing up in plain text. I get enough spam already! (-:

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Any idea when we are going to get a fix for this? It's beginning to affect more and more of my users -- it was just isolated to a couple but now it seems to be growing. Definitely an iOS 13.x thing. None of the iOS 12.x users have experienced it. I spend more time explaining to users that it's an iOS/Apple bug (for which I can't get around) than I do working on the product. Rebooting is the only thing that will work around it -- and then only temporarily until it pops up again.

Hi,

Xcode has finally fixed this issue in the latest release. Please update to Xcode Version 11.3.1


Thanks,

Jitender

I am on the same boart here.. wondering when the fix is coming....

Submitted FB7845669 as this is still not working even in 13.5.1.

Is the problem completely fixed? There are still customer service feedback on this issue.

Is the problem completely fixed?

I think so. Certainly, the absence of traffic on this thread suggests that it’s working for most folks.

Two things:

  • As CNCopyCurrentNetworkInfo has been deprecated, I recommend that you move over to NEHotspotNetwork.fetchCurrent(completionHandler:).

  • If you continue to have problems after that, start a new thread with the details. Tag it with NetworkExtension so that the right folks see it.

Note While the official docs for fetchCurrent(completionHandler:) leave a lot to be desired, there’s a bunch of useful doc comments in the <NetworkExtension/NEHotspotNetwork.h> header.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

@eskimo as of 2022-02-25, we came across this thread from another article saying calling CNCopyCurrentNetworkInfo will lead to massive memory leak, with Xcode 13.2.1, iOS 14, while the app has no location auth and call this API. It will return NULL, and lots of internal objects leak, please see attached screenshot.

our test code:

for (int i = 0; i < 100000; i++) {
        @autoreleasepool {
            NSString *ssid = [UIDevice currentWifiSSID];
            NSString *bssid = [UIDevice currentWifiBSSID];
        }
    }

currentWifiBSSID will be like:

    NSArray *interfaces = (__bridge_transfer NSArray *)CNCopySupportedInterfaces();
    NSString *ssidStr = nil;
    for (NSString *name in interfaces) {
        NSDictionary *networkInfo = (__bridge_transfer NSDictionary *)CNCopyCurrentNetworkInfo((__bridge CFStringRef)name);
        ssidStr = [networkInfo objectForKey:(__bridge NSString *)kCNNetworkInfoKeySSID];
        if([ssidStr isKindOfClass:[NSString class]] && ssidStr.length > 0) {
            return ssidStr.copy;
        }
    }
    return nil;
}

Any plan to fix CNCopyCurrentNetworkInfo?

Any plan to fix CNCopyCurrentNetworkInfo?

While it’s reasonable to file a bug about the memory leak, note that CNCopyCurrentNetworkInfo has been deprecated in favour of the shiny new NEHotspotNetwork.fetchCurrentWithCompletionHandler: method. Does that also leak?

If you do file a bug, please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

@eskimo is fetchCurrentWithCompletionHandler synchronous or aysnchronous in terms of the completion handler? e.g. Our code base using CNCopyCurrentNetworkInfo is synchronous, but if fetchCurrentWithCompletionHandler is aysnchronous for the completion handler, our code base might have a problem.

And in terms of mem leak, thew shiny new API is still proposing leaking, I only write a simple for loop with a pool:

   for (int i = 0; i < 100000; i++) {
    @autoreleasepool {
      [NEHotspotNetwork fetchCurrentWithCompletionHandler:^(NEHotspotNetwork * _Nullable currentNetwork) {
        NSString *ssid = currentNetwork.SSID;
        NSString *bssid = currentNetwork.BSSID;
        NSString *network = [[NSString alloc] initWithFormat:@"%@,%@", ssid, bssid];
      }];
    }
  }

I'm not sure if it's real leaks. I filed both API with bug number 9936268: https://feedbackassistant.apple.com/feedback/9936268

FB9936268> is +fetchCurrentWithCompletionHandler: synchronous or aysnchronous

in terms of the completion handler?

Async.

I'm not sure if it's real leaks.

It certainly looks that way.

FB9936268

Thanks.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"