Nehotspothelper Annotations Not Appearing

Why NEHotspotHelper registerWithOptions returning FALSE?

Check your app is signing with the correct entitlements file. You can do this with the following command:

codesign -d --entitlements :- /Users/User/Library/Developer/Xcode/DerivedData/appname-atpabrbgvqunorhiggpf/Build/Products/Debug-iphoneos/AppName.app

In the output, you should see the two following entitlements:

<key>com.apple.developer.networking.HotspotHelper</key>
<true/>
<key>com.apple.developer.networking.networkextension</key>
<array>

If you don't you can debug your codesigning process by following the thread here:

https://forums.developer.apple.com/message/75928#75928

Remember the hotspot helper code will only run on a device.

For reference, this code works for me (Swift)

var options = [String: NSObject]()
options[kNEHotspotHelperOptionDisplayName] = "Try Here" as NSObject?

NSLog("Lets register", "")
let returnType = NEHotspotHelper.register(options: options, queue: DispatchQueue.main, handler: {(_ cmd: NEHotspotHelperCommand) -> Void in

NSLog("Returned", "")

print(cmd)

if cmd.commandType == NEHotspotHelperCommandType.evaluate || cmd.commandType == NEHotspotHelperCommandType.filterScanList {

if cmd.networkList != nil {

for network: NEHotspotNetwork in cmd.networkList! {

NSLog("Found network \(network.bssid) with \(network.ssid)", "")

if (network.ssid == "Hub") {

print("Confidence set to high for ssid:\(network.ssid)")
}
}

}

}
})

NEHotspotHelper issue trying to authenticate network on iOS

I found a solution. Instead of creating a response when the ssid is found what I've done is to create an array and add the networks matching my ssid and then call createResponse: setting all the networks in my array:

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:@"Try here", kNEHotspotHelperOptionDisplayName, nil];

dispatch_queue_t queue = dispatch_queue_create("com.myapp.ex", 0);

BOOL isAvailable = [NEHotspotHelper registerWithOptions:options queue:queue handler: ^(NEHotspotHelperCommand * cmd) {

NSMutableArray *hotspotList = [NSMutableArray new];

if(cmd.commandType == kNEHotspotHelperCommandTypeEvaluate || cmd.commandType == kNEHotspotHelperCommandTypeFilterScanList) {

for (NEHotspotNetwork* network in cmd.networkList) {

if ([network.SSID isEqualToString:@"MySSID"]) {

[network setConfidence:kNEHotspotHelperConfidenceHigh];
[network setPassword:@"mypassword"];

NSLog(@"Confidence set to high for ssid: %@ (%@)\n\n", network.SSID, network.BSSID);

[hotspotList addObject:network];
}
}

NEHotspotHelperResponse *response = [cmd createResponse:kNEHotspotHelperResultSuccess];
[response setNetworkList:hotspotList];
[response deliver];
}
}];

Now I can see "Try here" under the SSID name and I can join the network with no need for manually adding the password.



Related Topics



Leave a reply



Submit