if (@available(iOS 10.0, )) { // iOS 10及以上版本使用此方法 NEHotspotHelper helper = [NEHotspotHelper alloc] initWithQueue:dispatch_get_main_queue()]; [helper setCallbackQueue:dispatch_get_main_queue()]; [helper registerWithOptions:nil queue:dispatch_get_main_queue() handler: ^(NEHotspotHelperCommand * cmd) { for (NEHotspotNetwork* network in cmd.networkList) { if ([network.SSID isEqualToString:@"YOUR_SSID"]) { [network setConfidence:NEHotspotHelperConfidenceHigh]; [network setPassword:@"YOUR_PASSWORD"]; NEHotspotHelperResponse *response = [cmd createResponse:kNEHotspotHelperResultSuccess]; [response setNetworkList:@[network]]; [response deliver]; } } }]; } else { // iOS 8, 9使用此方法 NSString *URLString = @"http://apple.com/library/test/success.html"; NSURL *URL = [NSURL URLWithString:URLString]; NSURLRequest *URLRequest = [NSURLRequest requestWithURL:URL]; [NSURLConnection sendAsynchronousRequest:URLRequest queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) { if (response && data) { // 成功连接到网络