Reputation: 841
I am trying to get my mobile app to connect to a Wifi network (for configuration purposes). This should be possible as of iOS 11 through the NEHotspotConfiguration
& NEHotspotConfigurationManager
classes.
The problem is that I keep getting an Internal Error (error code 8) and I don’t get a user prompt to ask for permission to connect to wifi network. I have already set the Hotspot Configuration capability in Xcode that the NEHotspotConfigurationManager class requires. Also worth mentioning that I am testing this on a real device only, since the iOS simulator does not support wifi.
Although I am using the NativeScript framework, it seems that this is more of an issue with the underlying iOS platform.
So far I have this code:
this.wifiManager = NEHotspotConfigurationManager.new();
this.wifiConfig = NEHotspotConfiguration.alloc().initWithSSID(this.config.wifi.SSID);
this.wifiConfig.joinOnce = true;
this.wifiManager.applyConfigurationCompletionHandler(this.wifiConfig, (error: NSError) => {
if (error && error.code!==NEHotspotConfigurationError.AlreadyAssociated) {
console.log(`wifiManager.applyConfigurationCompletionHandler error code ${error.code}: ${error.localizedDescription}`);
} else {
console.log(`wifiManager.applyConfigurationCompletionHandler success!`);
}
});
Thanks in advance!
P.S. this post suggest that it might just be an issue on the device itself and that a device restart should solve the issue but that is not the case for me
Upvotes: 3
Views: 2151
Reputation: 1659
In case somebody stumbles upon this question in the future
TL;DR Bug in iOS - Hopefully fixed in 12.2 - restart iPhone on older iOS versions
We had this problem too although we set the correct capability. The internal error was thrown until we restarted the phone. Until today we have not understood when or how this broken state was reached.
Luckily there was a discussion in the Apple Developer forums where @eskimo answered:
eskimo Nov 27, 2018 12:59 PM:
Folks keep tripping over this so I thought I’d post an update. As others have noted above we have a bug to track this issue (r. 42919071). Right now I can’t offer any predictions as to when this will be fixed. Moreover, I don’t have any solid workaround suggestions.
I should stress that the symptoms of this bug persist until the device is restarted. If you encounter this error transiently — that is, you get the error and then, later on, things work without having to restart the device
It also looks like this bug was fixed in iOS 12.2
~eskimo Feb 21, 2019 9:24 AM:
If you’ve hit this problem in the past I’d appreciate you retesting on the latest iOS 12.2 beta seed. We’ve made some changes there to fix this issue, and it’d be nice to know if they’re working as expected.
Source: https://forums.developer.apple.com/thread/107851
Upvotes: 0
Reputation: 1807
I just tried your code and it worked exactly like this. I got internal error code 8 too, then I enabled the hotspot configuration capability and deployed to my iOS 11 device. It immediately showed the required dialog.
Here's my complete code:
constructor() {
let configManager = NEHotspotConfigurationManager.new();
let config = NEHotspotConfiguration.alloc().initWithSSID('Guest');
config.joinOnce = true;
configManager.applyConfigurationCompletionHandler(config, (error: NSError) => {
if (error && error.code !== NEHotspotConfigurationError.AlreadyAssociated) {
console.log(`wifiManager.applyConfigurationCompletionHandler error code ${error.code}: ${error.localizedDescription}`);
} else {
console.log(`wifiManager.applyConfigurationCompletionHandler success!`);
}
});
}
Upvotes: 2