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
What's the Equivalent of the Uisplitviewcontroller in Swiftui
Could Not Find an Overload for "Init" That Accepts the Supplied Arguments in Swift
Swift - Image Data from Ciimage Qr Code/How to Render Cifilter Output
How to Pass Data from One Container to Another, Both Embedded in the Same Uiviewcontroller in Swift
Auto Adjust Custom Uitableviewcell and Label in It to the Text
Set a Maximum Number of Children in Firebase
iOS 9 Orientation Auto-Rotation Animation Not Working, But Always on Main Thread
Reverse an Audio File Swift/Objective-C
How to Consecutively Present Two Alert Views Using Swiftui
How to Create Otp Verification Screen and Detect Delete Backward on Multiple Uitextfield Is Swift
Getter VS Computed Property. What Would Warrant Using One of These Approaches Over the Other
Disable Swipe Back Gesture in Swift
Is iOS Carplay API Public? How to Integrate Carplay
How to Implement Two Inits with Same Content Without Code Duplication in Swift
How to Draw Radial Gradients in a Calayer