CNCopyCurrentNetworkInfo getting nil when app is created through command line tools

My app's deployment target is iOS 13. So I am using CNCopyCurrentNetworkInfo for getting the wifi SSID information. I am facing a strange issue only when I archive and distribute my enterprise app through command line tools. The wifi SSID info is always getting nil when the app is created through command line tools. There are no issues when I archive the app from XCode.

Commands that I have used for creating and exporting the archive are:

  • xcodebuild -workspace MyWorkspace.xcworkspace -scheme MyScheme archive -configuration MyConfig -sdk iphoneos -archivePath MyArchivePath CODE_SIGNING_ALLOWED=NO
  • xcodebuild -exportArchive -archivePath MyArchivePath -exportPath MyExportPath -exportOptionsPlist MyExportOptionPlist

Note: I have added all the necessary entitlements and other info for the ssid access like

  • Privacy - Location When In Use Usage Description
  • Access WiFi Information in entitlements

Am I missing something here?

The most likely culprit is the com.apple.developer.networking.wifi-info entitlement. Unpack you .ipa and then check the entitlements on your app:

% codesign -d --entitlements - /path/to/your.app

What do you see?

Share and Enjoy

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

I can see the <key>com.apple.developer.networking.wifi-info</key> in my entitlements when I unpack the .ipa file

Hmm, interesting.

To investigate further I recommend that you split the problem in two. Right now you’re doing two things from the command line:

  1. Building your Xcode archive

  2. Exporting your Xcode archive

To find out which is the problem:

  • Build an archive with Xcode and then export it from the command line

  • Build an archive from the command line and then export it with Xcode

Share and Enjoy

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

I have already tried archiving from XCode and exporting the archive with command-line tools. In that scenario, I am not seeing the issue. So, it looks like some issue with the archive command.

Accepted Answer

So, it looks like some issue with the archive command.

OK.

Going back to your first post, you wrote:

xcodebuild … CODE_SIGNING_ALLOWED=NO

What’s up with that CODE_SIGNING_ALLOWED option? That’s not how the Xcode app does things. Specifically, when you archive from the app, the app in the archive will typically be signed with your Apple Development signing identity.

If you drop that option, does it fix things?

Keep in mind that exporting from the archive tries to preserve entitlements. But entitlements are carried by the code signature, so if the app in the archive isn’t signed then there’s nothing to preserve.

Share and Enjoy

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

This fixed my issue. I have dropped the CODE_SIGNING_ALLOWED option. Thank you so much!

CNCopyCurrentNetworkInfo getting nil when app is created through command line tools
 
 
Q