Doubts about NetworkExtension

Hi.

I have been using NetworkExtension and I am having some doubts, and need help.

In my entitlements is set:


<key>com.apple.developer.networking.HotspotHelper</key>

<true/>

<key>com.apple.external-accessory.wireless-configuration</key>

<true/>


I set in the Info.plist:

<key>UIBackgroundModes</key>

<array>

<string>network-authentication</string>

</array>


In my controller I configured:

NSArray * networkInterfaces = [NEHotspotHelper supportedNetworkInterfaces];

NSLog(@"Networks %@",networkInterfaces);


But the return is nil.


I also tried register NEHotspotHelp, and after I have used [NEHotspotHelper supportedNetworkInterfaces] but return only the network connected.

NSMutableDictionary* options = [[NSMutableDictionary alloc] init];

[options setObject:@"Hotspot" forKey:kNEHotspotHelperOptionDisplayName];


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

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

}];

NSArray * networkInterfaces = [NEHotspotHelper supportedNetworkInterfaces];

NSLog(@"Networks %@",networkInterfaces);


Is possible list nearby networks in my application, without enter in the screen of Settings/Wifi?

When use [NEHotspotHelper supportedNetworkInterfaces] may I list all nearby networks?


Thanks.

Michel de Sousa

Replies

Is possible list nearby networks in my application, without enter in the screen of Settings/Wifi?

When use [NEHotspotHelper supportedNetworkInterfaces] may I list all nearby networks?

NEHotspotHelper was not designed as a general purpose ‘list nearby Wi-Fi networks’ API. Rather, it was designed to allow folks to build apps that help the user navigate Wi-Fi hotspots. As such, it only provides the hotspot helper with the minimum amount of information required to achieve that goal.

Part of that design is a ‘don’t call us, we’ll call you’ approach, where the Wi-Fi subsystem only calls your code if it’s actively looking for a Wi-Fi network to join. In that case it will run the discovered networks through your helper via the

.FilterScanList
command.

OTOH, if the device is happily associated with a fully working Wi-Fi, there’s no need for it to look for a Wi-Fi network to join and thus your hotspot helper does not get called.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

So, if the device didn't have connected in neither WI-Fi and I have registered NEHotspotHelp in this way:

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

if(cmd.commandType == kNEHotspotHelperCommandTypeFilterScanList) {

for (NEHotspotNetwork* network in cmd.networkList) {

NSLog(@“%@“, network.SSID);

}

}

}];

The callback will call automatic? Or I need enter in the screen of Settings/Wifi to "force" the callback?

Thanks a lot

Michel de Sousa

The callback will call automatic?

Yes, kinda. To be clear, the API makes no guarantees about when it will send you the

.FilterScanList
command. Rather, the system will send you that command when it detects a new network for which it needs to know the hotspot state.

As I said, it’s ‘don’t call us, we’ll call you’.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

But I need enter in the screen of Settings/WIFI to call the callback?

But I need enter in the screen of Settings/WIFI to [have the callback called]?

Yes, kinda. One way to force the system to do a full Wi-Fi scan (and hence pass the results to your hotspot helper via a

.FilterScanList
command) is to open Settings > Wi-Fi. However, there are other times when the system will call your helper with the
.FilterScanList
command. As I said, the system makes no guarantees as to when this will happen.

If your high-level goal is to scan for nearby Wi-Fi networks, NEHotspotHelper is not the right API to use. It was specifically designed for hotspot helpers, not as a general-purpose Wi-Fi scanning API.

Then again, if your high-level goal is scan for nearby Wi-Fi networks, you’re in trouble because there is no public API for doing this.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

That I can not get WiFi Network Extension list near?

No such api?

That I can not get WiFi Network Extension list near?

Correct.

Your hotspot helper could try to infer that information from the

.FilterScanList
commands that it gets, but that’s not the same as actively scanning for Wi-Fi networks, or even having direct access to the current Wi-Fi scan list. Both of those were explicit non-goals of the hotspot helper API, which was designed to allow folks to build hotspot helpers, not to provide a general-purpose Wi-Fi scanning function.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

obtain Wi-Fi information to go through NEHotspotHelper?

Such as WiFi signal strength and SSID

Hi eskimo, will system launch my app in backgroud to call the HotspotHelper callback when the user enter the screen of Settings/WIFI even if my app is force quited by user?

Hi Quinn,

Today i got my developer account added with Network Extension entitlement, i am successfully able to Annotate Wifi networks in the WiFi network scanner , but i noticed that callback to

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

{

//callback

if(cmd.networkList)

{

//networkList

}

}

received only if the user opens the Settings -> Wi-Fi manually, then i’m able to get callback cmd.networkList . Is there a way i get the list without user having to go to Settings?. At least for the first launch? (Already folks had same doubt above). Currently supportedNetworkInterfaces resulting in an array containing exactly one NEHotspotNetwork object that is current wifi network to which device connected.

i noticed that callback [is] received only if the user opens the Settings -> Wi-Fi manually, then i’m able to get callback cmd.networkList . Is there a way i get the list without user having to go to Settings?

Didn’t I already cover this is my May 23 and May 24 posts?

The hotspot helper API was designed to allow developers to write an app that helps users log on to hotspots. If that’s what your app does, why do you need to get filter results when the device isn’t looking for a hotspot?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hi Quinn,

I made a simple demo just implementing the "registerWithOptions: queue: handler: " function, deliver success and high confidence respone to every commond but .scanList. I found the auto-join wifi feature was delayed. in normal when switch on the wifi, the wifi would auto-join in 3 second, but the demo make it delay 2 second at least. What's wrong? Thank you.

Here is the code:

- (void)registerHotspotHelper {
    NSMutableDictionary *options = [[NSMutableDictionary alloc] init];
    [options setObject:@"TestDemo" forKey:kNEHotspotHelperOptionDisplayName];
    queue = dispatch_queue_create("com.tester.NetworkDemo", 0);
    BOOL returnType = [NEHotspotHelper registerWithOptions:options queue:queue handler:^(NEHotspotHelperCommand *cmd) {
        NSLog(@"CommandType: %zd", cmd.commandType);
        tmpCmd = cmd;
        switch (cmd.commandType) {
            case kNEHotspotHelperCommandTypeFilterScanList:
            {
                //Do something with ScanList
            }
                break;
            case kNEHotspotHelperCommandTypeEvaluate:
            case kNEHotspotHelperCommandTypeMaintain:
            {
                NEHotspotNetwork *network = cmd.network;
                [network setConfidence:kNEHotspotHelperConfidenceHigh];
                NEHotspotHelperResponse *response = [cmd createResponse:kNEHotspotHelperResultSuccess];
                [response setNetwork:network];
                [response deliver];
            }
                break;
            case kNEHotspotHelperCommandTypeAuthenticate:
            {
                NEHotspotNetwork *network = cmd.network;
                [network setConfidence:kNEHotspotHelperConfidenceHigh];
                NEHotspotHelperResponse *response = [cmd createResponse:kNEHotspotHelperResultAuthenticationRequired];
                [response setNetwork:network];
                [response deliver];
            }
                break;
            case kNEHotspotHelperCommandTypePresentUI:
            {
                NEHotspotNetwork *network = cmd.network;
                [network setConfidence:kNEHotspotHelperConfidenceHigh];
                NEHotspotHelperResponse *response = [cmd createResponse:kNEHotspotHelperResultUIRequired];
                [response setNetwork:network];
                [response deliver];
            }
                break;
            default:
                break;
        }
    }];

    NSLog(@"Register Result: %d", returnType);
}

Hi Eskimo


so is not possible to retrieve the list of RSSI associated to wifi SSIDs?


thanks