Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
422 views
in Technique[技术] by (71.8m points)

ios - NEHotspotHelper annotations not appearing

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 annotation below the SSID name in the Wifi settings screen. We are on ios 9 Beta 3, xcode 7 beta 3.

We have done these steps successfully:

  • @note 1 The application's Info.plist MUST include a UIBackgroundModes array ?*?? containing 'network-authentication'.

  • @note 2 ?*?? The application MUST set 'com.apple.developer.networking.HotspotHelper' ?*?? as one of its entitlements. The value of the entitlement is a boolean ?*?? value true.

Here's our code in the App. We are trying to annotate a SSID by the name of "Internet" by a text "Try Here". We get the log that the setConfidence method is called for SSID "Internet". Yet, we do not see the actual annotation in the Wifi selection screen.

We also tried to pass 'nil' for the options object which promised to show the App name as the default annotation. But we do not see that either. We get return 'true' for the call to method registerWithOptions() and we do get callbacks when we open the wifi settings screen

?

NSMutableDictionary* options = [[NSMutableDictionary alloc] init]; 
[options setObject:@"Try Here" forKey:kNEHotspotHelperOptionDisplayName]; 
?dispatch_queue_t queue = dispatch_queue_create("com.myapp.ex", 0); 
BOOL returnType = [NEHotspotHelper registerWithOptions:options queue:queue 
handler: ^(NEHotspotHelperCommand * cmd) { 
??? if(cmd.commandType == kNEHotspotHelperCommandTypeEvaluate || cmd.commandType == kNEHotspotHelperCommandTypeFilterScanList ) { 
???????? 
??????? for (NEHotspotNetwork* network? in cmd.networkList) {? 
??????????? if ([network.SSID isEqualToString:@"Internet"]){ 
??????????????? [network setConfidence:kNEHotspotHelperConfidenceHigh]; ????????????? 
??????????????? NSLog(@"Confidance set to high for ssid:%@",network.SSID); 
??????????? }? 
??????? } ?? 
??? } 
}];

=========================

Please help us to understand what we are missing ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:@"<wifi-password>"];                    
                [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 enter image description here
  4. In Info.plist add network-authentication key to Required background modes array enter image description here Hope that helps. Thanks

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...