How can I get WiFi SSID in Mac Catalyst?

I just want Mac Catalyst app can look up the SSID of the currently connected WiFI. Xcode returns I can't use CoreWLan in Mac Catalyst, so I used NEHotspotNetwork, although I do not have convince whether Mac Catalyst allows it.

The same code of destination works fine on iPhone, but not on Mac Catalyst and Mac(Designed for iPad).

What is the proper way to get SSID of WiFI in Mac Catalyst? Is there another way to do this?

The code I tried is below and I used CoreLocation API before call this function.

func getWiFiSsid() {
        NEHotspotNetwork.fetchCurrent { network in
                            if let network = network {
                                print(network)
                            } else {
                                print("network is nil!")
                            }
                        }
    }

Below is Entitlement file. Entitlements for app sandbox is removed when I run in Mac(Designed for iPad).

 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>com.apple.developer.networking.HotspotConfiguration</key>
	<true/>
	<key>com.apple.developer.networking.networkextension</key>
	<array/>
	<key>com.apple.developer.networking.wifi-info</key>
	<true/>
    <key>com.apple.security.app-sandbox</key>
	<true/>
	<key>com.apple.security.network.client</key>
	<true/>
	<key>com.apple.security.network.server</key>
	<true/>
	<key>com.apple.security.personal-information.location</key>
	<true/>
</dict>
</plist>

Below is Info.plist file.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>CFBundleDevelopmentRegion</key>
	<string>$(DEVELOPMENT_LANGUAGE)</string>
	<key>CFBundleExecutable</key>
	<string>$(EXECUTABLE_NAME)</string>
	<key>CFBundleIdentifier</key>
	<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
	<key>CFBundleInfoDictionaryVersion</key>
	<string>6.0</string>
	<key>CFBundleName</key>
	<string>$(PRODUCT_NAME)</string>
	<key>CFBundlePackageType</key>
	<string>APPL</string>
	<key>CFBundleShortVersionString</key>
	<string>1.0</string>
	<key>CFBundleVersion</key>
	<string>1</string>
	<key>LSRequiresIPhoneOS</key>
	<true/>
	<key>UILaunchStoryboardName</key>
	<string>LaunchScreen</string>
	<key>UIMainStoryboardFile</key>
	<string>Main</string>
	<key>UIRequiredDeviceCapabilities</key>
	<array>
		<string>armv7</string>
	</array>
	<key>UISupportedInterfaceOrientations</key>
	<array>
		<string>UIInterfaceOrientationPortrait</string>
		<string>UIInterfaceOrientationLandscapeLeft</string>
		<string>UIInterfaceOrientationLandscapeRight</string>
	</array>
	<key>UISupportedInterfaceOrientations~ipad</key>
	<array>
		<string>UIInterfaceOrientationPortrait</string>
		<string>UIInterfaceOrientationPortraitUpsideDown</string>
		<string>UIInterfaceOrientationLandscapeLeft</string>
		<string>UIInterfaceOrientationLandscapeRight</string>
	</array>
	<key>NSLocationUsageDescription</key>
	<string>Determine whether the ssid of current Wi-Fi connection</string>
	<key>NSLocationWhenInUseUsageDescription</key>
	<string>Determine whether the ssid of current Wi-Fi connection</string>
</dict>
</plist>

The console log is below.

NEHotspotNetwork nehelper sent invalid result code [1] for Wi-Fi information request

I don’t think there’s a good way to do that:

  • NEHotspotNetwork is an iOS technology; it work work on the Mac.

  • The Mac API, Core WLAN, isn’t supported in a Catalyst app.

You might be able to make this work by creating a Mac command-line tool that calls Core WLAN and then running that from your Catalyst app using Process. However, I’m not 100% that’ll work because of the Location privilege requirement. For it to work the system would have to be able to determine that your app is the responsible code for your command-line tool for the purposes of the Location privilege. That usually works, but I’ve definitely seen cases where it fails.

Still, it’s worth giving it a whirl.

Share and Enjoy

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

How can I get WiFi SSID in Mac Catalyst?
 
 
Q