Connect to WiFi programmatically in ios

后端 未结 4 1231
余生分开走
余生分开走 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

    I ran into this issue last year and after quite a bit of digging I came across a helpful example called SOLStumbler. For this app to work your device must be jailbroken. I modified SOLStumbler and threw up a sample app on github. It uses the IPConfiguration bundle to access Apple80211 framework, which allows you to associate to a network. The readme contains the custom build instructions.

    https://github.com/devinshively/wifiAssociate

    0 讨论(0)
  • 2021-01-01 05:57

    We can programmatically connect wifi networks after iOS 11 public API. You can connect wifi using SSID and password like following.

    Swift

    var configuration = NEHotspotConfiguration.init(ssid: "wifi name", passphrase: "wifi password", isWEP: false)
    configuration.joinOnce = true
    
    NEHotspotConfigurationManager.shared.apply(configuration) { (error) in
        if error != nil {
            //an error occurred
            print(error?.localizedDescription)
        }
        else {
            //success
        }
    }
    

    Don't forget import NetworkExtension.

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2021-01-01 06:08

    It's possible in any version of iOS which can load a configuration profile: the app needs to generate a profile with the desired network credentials, and host a web server which provides the profile to Mobile Safari.

    0 讨论(0)
提交回复
热议问题