MacOS Add new WiFi profile programmatically

Hello,

I'm struggling to find a way, on how to add a new WiFi profile (SSID & password, that are in System Preferences > Network > Wi-Fi > Preferred Networks) programmatically, on MacOS (preferably something that'd work on obj c).

This is if some device would host a wifi hotspot, the Mac could connect to it automatically, or atleast the password would be already present (assuming there's no wifi connection already present).

Replies

In a mac Catalyst app, you could try creating an NEHotspotConfiguration for your WiFi network, then "apply" it using NEHotspotConfigurationManager.

I'm not sure if that would work, but it might be worth a try.

  • Hi, thank you for the suggestion.

    This was the first thing I've found when looking this topic up, however my project is native Mac, so when I try to use this object, I get "NEHotspotConfiguration' is unavailable: not available on macOS" error.

    I'll look into it, but I'm not sure if changing my project to "Mac Catalyst" is an option though. Would still prefer to find a native MacOS solution.

Add a Comment

In a mac Catalyst app, you could try creating an NEHotspotConfiguration for your WiFi network, then "apply" it using NEHotspotConfigurationManager.

You will run into issues using NEHotspotConfiguration in Mac Catalyst because while the symbols are available, the entitlements for:

<key>com.apple.developer.networking.HotspotConfiguration</key>
<true/>
<key>com.apple.developer.networking.wifi-info</key>
<true/>

Regarding:

I'm struggling to find a way, on how to add a new WiFi profile (SSID & password, that are in System Preferences > Network > Wi-Fi > Preferred Networks) programmatically, on MacOS (preferably something that'd work on obj c).

You could try looking a associateToNetwork in CoreWLAN on the macOS side to see if this gets you closer to what you are looking for.

Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com
  • Thanks @meaton, so NEHotspot... is marked as available in Catalyst, but it doesn't actually work. That's worth knowing!

  • Unfortunately, yes. The symbols are available, but the API does not work.

Add a Comment

Hello @meaton, thank you for your answer!

You could try looking a associateToNetwork in CoreWLAN on the macOS side to see if this gets you closer to what you are looking for.

I've tried to use associateToNetwork, and it works if it's an existing Network (aka currently available). However, at the time of this operation, I'm configuring the device, and it's network (WiFi) is not available yet.

I've tried digging through Core WLAN framework, but it doesn't seem like it's possible to associate to not available network. Do you have any other tips on leads, regarding this issue?