iOS - 如何使用私有/第三方库以SSID和密码以编程方式连接到WiFi网络 [英] iOS - How to programmatically connect to a WiFi network given the SSID and Password using a private/3rd party library

查看:670
本文介绍了iOS - 如何使用私有/第三方库以SSID和密码以编程方式连接到WiFi网络的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试复制我在iOS上创建的现有Android应用程序。在我的应用程序中,我应该能够在给定SSID和密码的情况下连接到WiFi网络。 SSID和密码可以是硬编码的或者可以由用户输入。我正在通过互联网研究如何在iOS上完成这项工作,但是,似乎这种行为非常气馁,并且没有办法使用公共/文档库来实现这一点,这些库不会让您的应用程序被拒绝App Store。

I am trying to replicate an existing Android Application that I made to iOS. In my application, I should be able to connect to a WiFi network given the SSID and the Password. The SSID and the Password can be hardcoded or can be inputted by the user. I was going through the internet to research on how this can be done on the iOS, however, it seems that this behavior is highly discouraged and that there's no way on doing this using public/documented libraries that won't get your application rejected by the App Store.

事情是我将亲自使用这个应用程序,我不打算将它提交到App Store,所以如果我使用外部设备就可以了库。如果我的朋友想要使用它,我可以导出企业ipa并给他们如何安装它的说明。

The thing is I'll be using this application personally and I don't plan on submitting it to the App Store so it's okay if I use external libraries. If my friends would want to use it, I could export an enterprise ipa and give them instructions on how to install it.

搜索时,似乎 MobileWifi.framework 是一个很好的候选人。但是,考虑到SSID和密码,似乎没有一种直接使用此库连接到WiFi网络的方法。

Upon searching, it seemed that MobileWifi.framework was a good candidate. However, it does not seem that there's a straightforward way of using this library to connect to a WiFi network given the SSID and the Password.

是否有人成功尝试过给定SSID和密码连接到Wifi网络?很感谢任何形式的帮助。

Is there anyone who has successfully tried to connect to a Wifi Network given the SSID and Password? Any help is very much appreciated.

推荐答案

在iOS 11中,Apple提供了公共API,您可以使用它以编程方式加入WiFi网络,而无需离开您的应用程序。

With iOS 11, Apple provided public API you can use to programmatically join a WiFi network without leaving your app.

您需要使用的课程称为 NEHotspotConfiguration

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

要使用它,您需要在应用功能中启用 Hotspot 功能(添加功能)。快速工作示例:

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-Name"];
configuration.joinOnce = YES;

[[NEHotspotConfigurationManager sharedManager] applyConfiguration:configuration completionHandler:nil];

这将提示用户加入SSID-NameWiFi网络。在用户离开应用程序之前,它将保持与WiFi连接。

This will prompt the user to join the "SSID-Name" 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.

> https://developer.apple.com/documentation/networkextension/nehotspotconfiguration

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

这篇关于iOS - 如何使用私有/第三方库以SSID和密码以编程方式连接到WiFi网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆