关于NetworkExtension iOS 9的疑问

时间:2016-05-19 17:46:48

标签: ios objective-c

我一直在使用NetworkExtension,我有些疑惑,需要帮助。 在我的权利中设置:

<key>com.apple.developer.networking.HotspotHelper</key>
<true/>
<key>com.apple.external-accessory.wireless-configuration</key>
<true/>

我在Info.plist中设置了:

<key>UIBackgroundModes</key>
<array>
<string>network-authentication</string>
</array>

在我的控制器中我编码:

NSArray * networkInterfaces = [NEHotspotHelper supportedNetworkInterfaces];
NSLog(@"Networks %@",networkInterfaces);

但回报是零。

我也尝试过注册NEHotspotHelp,之后我使用了[NEHotspotHelper supportedNetworkInterfaces],但只返回连接的网络。

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);

是否可以在我的应用程序中列出附近的网络,而无需进入设置/ Wifi屏幕?

使用[NEHotspotHelper supportedNetworkInterfaces]时,我可以列出附近的所有网络吗?

非常感谢。

Michel de Sousa

1 个答案:

答案 0 :(得分:2)

我解决了我的问题,但需要进入设置/ Wi-Fi屏幕。

我在我的应用程序中列出了附近的网络:

NSMutableDictionary* options = [[NSMutableDictionary alloc] init];
[options setObject:@"Connect using my app" forKey:kNEHotspotHelperOptionDisplayName];
dispatch_queue_t queue = dispatch_queue_create("com.myapp.wifi", 0);
[NEHotspotHelper registerWithOptions:optionsqueue:queue handler: ^(NEHotspotHelperCommand * cmd) {
if(cmd.commandType == kNEHotspotHelperCommandTypeFilterScanList){
    for (NEHotspotNetwork *eachNetwork in cmd.networkList) {
        // Get Informations of the network
        NSLog(@"%@", eachNetwork.SSID);
    }
}
}];