NEHotspotHelper annotations not appearing

后端 未结 3 927
暖寄归人
暖寄归人 2020-12-01 10:15

We tried out the new NetworkExtension API. We were successful in recreating all the steps in our app. But, we have an issue that we are still not seeing the custom annotatio

3条回答
  •  忘掉有多难
    2020-12-01 10:26

    I have implemented the below code for authenticating and annotating the Wifi hotspot with "Connect to MyWifi" for SSID "TP-LINK" from within the app, It works fine.

    NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:@"Connect to MyWifi", 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) {
                NSLog(@"network name:%@", network.SSID);
                if ([network.SSID isEqualToString:@"TP-LINK"]) {
                    [network setConfidence:kNEHotspotHelperConfidenceHigh];
                    [network setPassword:@""];                    
                    [hotspotList addObject:network];
                }
            }
    
            NEHotspotHelperResponse *response = [cmd createResponse:kNEHotspotHelperResultSuccess];
            [response setNetworkList:hotspotList];
            [response deliver];
        }
    }];
    

    Note: For the above code to work,

    1. you need to get entitlement access from apple by mailing them on networkextension@apple.com.
    2. Once you have the entitlement, you need to create new provisioning profile where you will have to add the network extension entitlement(available only if you have access) and use that profile in your xcode for it to work.
    3. Add entitlement com.apple.developer.networking.HotspotHelper to true in your entitlement file in your xcode
    4. In Info.plist add network-authentication key to Required background modes array Hope that helps. Thanks

提交回复
热议问题