Get SSID of current network for iOS 15.5

Below snippet is used to fetch SSID of current network.

__block NSString *ssid = nil;
dispatch_semaphore_t sem = dispatch_semaphore_create(0);
[NEHotspotNetwork fetchCurrentWithCompletionHandler:^(NEHotspotNetwork * _Nullable currentNetwork) {
      if( currentNetwork != nil) {
        ssid = [currentNetwork SSID];
      }
      dispatch_semaphore_signal(sem);
}];

We are getting proper currentNetwork information in the block. But when ssid is fetched from outside the block, it is getting invalid after the block exits. We are getting bad NSString object.

This issue occurs only on iOS 15.5 beta version or later. Same code snippet worked perfectly for earlier versions of iOS.

Can you help why it occurs only on iOS 15.5 or later versions?

Note: Requirement according to https://developer.apple.com/forums/thread/679038 is fulfilled

I’m going to ask the same question I asked on your other thread:

  • With regards the code you posted, that’s being compiled into a framework, right?

  • Is that compiled with ARC? Or with MRR?

Share and Enjoy

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

About your query:

  • Yes, that’s being compiled into a framework and the framework is being used in iOS project
  • Project is compiled with ARC

With ARC enabled I can’t see any obvious cause for this. When your code assigns a value to ssid, ARC should take a strong reference to the string which should persist until you read it after the dispatch_semaphore_wait.

If you put this code into a new test app, does it fail in the same way?

If you change this line:

    ssid = [currentNetwork SSID];

to this:

    ssid = [[currentNetwork SSID] copy];

does the problem go away?

Regardless, I think you should file a bug about this. Given that this is a iOS 15.5 beta regression, and there’s nothing obviously wrong with your code, that warrants a bug report.

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"

Get SSID of current network for iOS 15.5
 
 
Q