iOS APP内WiFi配置相关
来源:互联网 发布:京东首届网络电影节 编辑:程序博客网 时间:2024/06/05 07:32
在网上搜了好多例子,也问了好多人,最终无果,特将自己找到的资源做分享
本人做智能家居的APP,智能硬件设备自带WiFi(局域网)。如果用户没有连接设备的WiFi进入APP时,需要提示用户去设置界面连接WiFi。
需求一、APP内部跳转到系统WIFi 界面手动连接
实现
info里面设置
在项目中的info.plist中添加 URL types 并设置一项URL Schemes为prefs,如下图:
实现代码
NSURL *url = [NSURL URLWithString:@"prefs:root=WIFI"];if ([[UIApplication sharedApplication] canOpenURL:url]){ [[UIApplication sharedApplication] openURL:url];}
需求二、在APP内部做切换网络
iOS端WIFI应用的相关开发,主要存在以下问题:
iOS系统WIFI相关的接口很少,大部分接口都是私有接口
在设备连接上WIFI,没有通过路由器认证前,如果关闭iOS自动弹出的Portal页面,iPhone的WIFI会自动断开
如何禁止iOS系统自动弹Portal页面
公共WIFI的名称确定及不确定时的处理办法
获取路由器Ip的方法1.添加getgateway.c文件,和route.h文件2.导入这些头文件#import <SystemConfiguration/CaptiveNetwork.h>#include <sys/socket.h>#import <netinet/in.h>#import <netinet6/in6.h>#import <arpa/inet.h>#import <ifaddrs.h>#include <netdb.h>#import "getgateway.h"#import <SystemConfiguration/SystemConfiguration.h>3.获取网络IP
//获取路由器地址-(NSString *)routerIp { NSString *address = @"error"; struct ifaddrs *interfaces = NULL; struct ifaddrs *temp_addr = NULL; int success = 0; success = getifaddrs(&interfaces); if (success == 0) { temp_addr = interfaces; while(temp_addr != NULL) { if(temp_addr->ifa_addr->sa_family == AF_INET) { if([[NSString stringWithUTF8String:temp_addr->ifa_name] isEqualToString:@"en0"]) { address = [NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)]; //广播地址--10.22.70.255 NSLog(@"广播地址--%@",[NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_dstaddr)->sin_addr)]); //本机地址--10.22.70.111 NSLog(@"本机地址--%@",[NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_addr)->sin_addr)]); //子网掩码地址--255.255.255.0 NSLog(@"子网掩码地址--%@",[NSString stringWithUTF8String:inet_ntoa(((struct sockaddr_in *)temp_addr->ifa_netmask)->sin_addr)]); //端口地址--en0 NSLog(@"端口地址--%@",[NSString stringWithUTF8String:temp_addr->ifa_name]); } } temp_addr = temp_addr->ifa_next; } } // Free memory freeifaddrs(interfaces); in_addr_t i =inet_addr([address cStringUsingEncoding:NSUTF8StringEncoding]); in_addr_t* x =&i; unsigned char *s=getdefaultgateway(x); NSString *ip=[NSString stringWithFormat:@"%d.%d.%d.%d",s[0],s[1],s[2],s[3]]; //路由器地址-----10.22.70.1 NSLog(@"路由器地址-----%@",ip); return ip;}
4.获取SSID-(NSDictionary *)fetchNetInfo{ NSArray *interfaceNames = CFBridgingRelease(CNCopySupportedInterfaces()); NSDictionary *SSIDInfo; for (NSString *interfaceName in interfaceNames) { SSIDInfo = CFBridgingRelease(CNCopyCurrentNetworkInfo((__bridge CFStringRef)interfaceName)); BOOL isNotEmpty = (SSIDInfo.count > 0); if (isNotEmpty) { break; } } return SSIDInfo;}
注意:iOS 10以后对调用系统权限更高,WiFi那块也做了新的协议
至此未完,有谁知道如何在程序内部连接指定热点之后断开连接在重新连接其他的网络的,敬请告知 1 0
- iOS APP内WiFi配置相关
- iOS WIFI 相关
- iOS - 硬件配置相关 - 获取WiFi的SSID(草稿)
- wifi相关配置
- ios app 应用内购买配置完全指南
- iOS APP上线相关
- 内支付一:ios app 应用内购买配置完全指南
- 『IOS』应用内(in-app purchase)付费相关记录
- ios app内发送短信
- iOS App内发送短信
- ios App内评价问题
- iOS app内测TestFlight
- 通过wifi离线推广ios app
- iOS 从app跳转至WiFi设置
- [iOS-GQiang]iOS app内发送短信
- iOS开发中WiFi相关功能总结
- ios开发中WIFI相关功能总结
- iOS开发中WiFi相关功能总结
- 数据类型转换的坑
- ReactNative-通过setState控制组件的更新和变化
- 三级-下拉菜单
- Extjs6开发环境搭建
- python操作Excel
- iOS APP内WiFi配置相关
- BZOJ 1224: [HNOI2002]彩票 搜索,上下界剪枝,前缀和优化
- UITableView代理方法解释
- Thinkphp搜索附带分页
- 缺少msvcr110.dll
- 题目1016:火星A+B
- python Sessions和Cookies区别
- spark向量矩阵的使用(scala)
- JDBC连接mySql数据库