Connect to WiFi programmatically in ios

后端 未结 4 1264
余生分开走
余生分开走 2021-01-01 05:25

My question is about private API in IOS. Is there some API to manage WiFi connection? For example I\'m using Apple80211.framework to scan WiFi networks but it\'s unusable fo

4条回答
  •  灰色年华
    2021-01-01 05:57

    No need for private API any more! With iOS 11, Apple provided a public API you can use to programmatically join a WiFi network without leaving your app.

    The class you’ll need to use is called NEHotspotConfiguration.

    To use it, you need to enable the Hotspot capability in your App Capabilities (Adding Capabilities). Quick working example :

    NEHotspotConfiguration *configuration = [[NEHotspotConfiguration
     alloc] initWithSSID:@“SSID”];
    configuration.joinOnce = YES;
    
    [[NEHotspotConfigurationManager sharedManager] applyConfiguration:configuration completionHandler:nil];
    

    This will prompt the user to join the “SSID” WiFi network. It will stay connected to the WiFi until the user leaves the app.

    This doesn't work with the simulator you need to run this code with an actual device to make it work.

    More informations here : https://developer.apple.com/documentation/networkextension/nehotspotconfiguration

提交回复
热议问题