Hello Eskimo,
Thanks for your fast reply. I add some more code to my response, and some more details on the problem.
-(void)initHotspotHelper {
NSMutableDictionary* options = [[NSMutableDictionary alloc] init];
[options setObject:@"Connect with MyWIFI" forKey:kNEHotspotHelperOptionDisplayName];
dispatch_queue_t queue = dispatch_queue_create("HotspotQueue", 0);
[NEHotspotHelper registerWithOptions:options queue:queue handler: ^(NEHotspotHelperCommand * cmd) {
NSLog(@"Hotspot command: %ld", (long)cmd.commandType);
if(cmd.commandType == kNEHotspotHelperCommandTypeEvaluate)
{
if(cmd.network && cmd.network.SSID)
{
if([currentSsid rangeOfString:@"MyWIFI"].location != NSNotFound)
{
NSLog(@"Associated network: %@ / %d", cmd.network.SSID, cmd.network.isChosenHelper);
NEHotspotHelperResponse *response = [cmd createResponse:kNEHotspotHelperResultSuccess];
[cmd.network setConfidence:kNEHotspotHelperConfidenceHigh];
[response setNetwork:cmd.network];
[response deliver];
}
}
}
else if (cmd.commandType == kNEHotspotHelperCommandTypeFilterScanList)
{
NSMutableArray* responseArray = [NSMutableArray array];
for (NEHotspotNetwork* network in cmd.networkList)
{
if(!network.SSID) continue;
NSString* ssid = [network.SSID stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if ([ssid rangeOfString:@"MyWIFI"].location != NSNotFound)
{
[network setConfidence:kNEHotspotHelperConfidenceHigh];
[responseArray addObject:network];
}
}
// any networks found we cover? then return them
if(responseArray.count > 0)
{
NEHotspotHelperResponse *response = [cmd createResponse:kNEHotspotHelperResultSuccess];
[response setNetworkList:responseArray];
[response deliver];
}
}
}];
}
This is the whole function I use to react on HotspotHelper commands. It's called in the ApplicationDelegate's didFinishWithLaunching function.
What happens is:
- The installed handler is called with the kNEHotspotHelperCommandTypeFilterScanList command when Settings -> Wifi is opened, and the appropriate networks are attributed with the "Connect with MyWIFI" text. The hotspot command logging at the beginning shows a command "1" for filter scan list. This works as expected.
- When I choose a network from the list of networks, the installed handler is called with the kNEHotspotHelperCommandTypeEvaluate command. The hotspot command logging at the beginning shows a command "2" for evaluate. The cmd.network value is the selected network, and if it is a "MyWIFI" SSID I set the confidence and the network in the response. However, the cmd.network.isChosenHelper value always is false, even if it is a network that has the "Connect with MyWIFI" text on it and I returned a confidence of "High" for.
- After I chose a MyWIFI network, I do not get an authenticate call in the handler. In fact, I never saw any other command in the handler than scan list or evaluate.
There are no other apps on the iPhone that claim any network handling (and I tried it on other iPhones as well), so why is my app never chosen as the one to handle the authentication? I suppose this is the base problem, as after the handler received the kNEHotspotHelperCommandTypeEvaluate command and I returned confidence "High" the captive portal pops up, which shouldn't happen, and the handler does not get the authenticate command, which should happen.
As written in my original post, the HotspotHelper entitlements are set, as well as the network-authentication background mode (I assume nothing would work if thoise are not present anyway). What I find really strange is that all seems to work as expected, just the step that the app gets chosen to handle the authentication is not happening.
Are there any other places in the app I have to do something to get this working? Or is there a mistake in the above code? Or could it be some setting / reaction on the router that can cause this wrong behaviour? There doesn't seem to be any more things the app can actively set on a NEHotspotHelper response, so right now I'm completely clueless on how to get it working or even debug the situation any further.