So I am working with some hardware that requires connecting to a wifi network before uploading the firmware file. However, I am not seeing any user permission prompt appear and the following error is logged:
2022-12-11 15:20:10.899927-0600 -[2054:22393] [] Failed to send a 9 message to nehelper: <dictionary: 0x213d2e530> { count = 1, transaction: 0, voucher = 0x0, contents = "XPCErrorDescription" => <string: 0x213d2e6c8> { length = 18, contents = "Connection invalid" } } 2022-12-11 15:20:10.899997-0600 -[2054:22393] [] NEHotspotConfigurationHelper failed to communicate to helper server. Hotspot switch failed: Error Domain=NEHotspotConfigurationErrorDomain Code=8 "internal error." UserInfo={NSLocalizedDescription=internal error.}
In short the process is:
- Connect to BLE device
- Tell device a firmware update will occur over wifi
- The device opens a hotspot network (with a configurable SSID/PW)
- The user is expected to connect to the BLE device's hotspot, but I am stuck here
- The firmware update is continued and completed over wifi
My code more or less is:
import NetworkExtension
// ...
NEHotspotConfigurationManager.shared.removeConfiguration(forSSID: deviceSerialNumber)
let wifiConfig = NEHotspotConfiguration(ssid: deviceSerialNumber, passphrase: deviceSerialNumber, isWEP: false)
// Not setting joinOnce or setting it to true does not change the bahavior
wifiConfig.joinOnce = false
wifiConfig.lifeTimeInDays = 1
// Using a background thread did not change the behavior
DispatchQueue.main.async {
NEHotspotConfigurationManager.shared.apply(wifiConfig) { error in
if (error != nil)
{
let alreadyConnected: Bool = (error! as NSError).domain == NEHotspotConfigurationErrorDomain && (error! as NSError).code == NEHotspotConfigurationError.alreadyAssociated.rawValue
if (!alreadyConnected)
{
AppLogger.log("Hotspot switch failed: \(error!)")
DispatchQueue.global(qos: .userInitiated).async {
// ...
}
return
}
}
DispatchQueue.global(qos: .userInitiated).async {
// ...
}
}
}
// ...
I currently have the following capabilities defined via an imported provisioning file:
- Access WiFi Information
- Hotspot Configuration
- In-App Purchase
- Keychain Sharing
- Media Device Discovery
- Network Extensions
- Wireless Accessory Configuration
Hardware tested on:
- Mac Mini M1 - MacOS Monterey 12.6
- iPhone X - iOS 15.7.1, same result with a different memory address for XPCError
I am very new to Apple development, so I'm probably missing something simple. Any advice will be appreciated.
Thank You!