IOS零碎技术整理(3)-获取wifi列表
1. 该功能实现基于MobileApple80211框架来进行开发,而目前该框架成为了私有框架,其中的API均为私有API。
如果使用这些API可能导致应用不能上app store或者ios版本升级过程中,可能对私有api不兼容,导致程序莫名的挂掉或数据获取失败
2. 终端必须越狱,且必须把程序部署到终端的/Applications目录下取得超级用户权限才能获得wifi的访问权限
代码
#import <Foundation/Foundation.h>
#import <CoreFoundation/CoreFoundation.h>
#include <dlfcn.h>
@interface SOLStumbler : NSObject {
NSMutableDictionary *networks; //Key: MAC Address (BSSID)
void *libHandle;
void *airportHandle;
int (*apple80211Open)(void *);
int (*apple80211Bind)(void *, NSString *);
int (*apple80211Close)(void *);
int (*associate)(void *, NSDictionary*, NSString*);
int (*apple80211Scan)(void *, NSArray **, void *);
}
- (NSDictionary *)networks; //returns all 802.11 scanned network(s)
- (NSDictionary *)network:(NSString *) BSSID; //return specific 802.11 network by BSSID (MAC Address)
- (void)scanNetworks;
- (int)numberOfNetworks;
@end
#import "SOLStumbler.h"
@implementation SOLStumbler
- (id)init
{
self = [super init];
networks = [[NSMutableDictionary alloc] init];
libHandle = dlopen("/System/Library/SystemConfiguration/IPConfiguration.bundle/IPConfiguration", RTLD_LAZY);
char *error;
if (libHandle == NULL && (error = dlerror()) != NULL) {
NSLog(@">>> error %s",error);
exit(1);
}
apple80211Open = dlsym(libHandle, "Apple80211Open");
apple80211Bind = dlsym(libHandle, "Apple80211BindToInterface");
apple80211Close = dlsym(libHandle, "Apple80211Close");
apple80211Scan = dlsym(libHandle, "Apple80211Scan");
apple80211Open(&airportHandle);
apple80211Bind(airportHandle, @"en0");
return self;
}
- (NSDictionary *)network:(NSString *) BSSID
{
return [networks objectForKey:@"BSSID"];
}
- (NSDictionary *)networks
{
return networks;
}
- (void)scanNetworks
{
NSLog(@"Scanning WiFi Channels...");
NSDictionary *parameters = [[NSDictionary alloc] init];
NSArray *scan_networks; //is a CFArrayRef of CFDictionaryRef(s) containing key/value data on each discovered network
apple80211Scan(airportHandle, &scan_networks, parameters);
NSLog(@"===-scan_networks-======%@",scan_networks);
for (int i = 0; i < [scan_networks count]; i++) {
[networks setObject:[scan_networks objectAtIndex: i] forKey:[[scan_networks objectAtIndex: i] objectForKey:@"BSSID"]];
}
NSLog(@"Scanning WiFi Channels Finished.");
}
- (int)numberOfNetworks
{
return [networks count];
}
- ( NSString * ) description {
NSMutableString *result = [[NSMutableString alloc] initWithString:@"Networks State: \n"];
for (id key in networks){
[result appendString:[NSString stringWithFormat:@"%@ (MAC: %@), RSSI: %@, Channel: %@ \n",
[[networks objectForKey: key] objectForKey:@"SSID_STR"], //Station Name
key, //Station BBSID (MAC Address)
[[networks objectForKey: key] objectForKey:@"RSSI"], //Signal Strength
[[networks objectForKey: key] objectForKey:@"CHANNEL"] //Operating Channel
]];
}
return [NSString stringWithString:result];
}
- (void) dealloc {
apple80211Close(airportHandle);
[super dealloc];
}
@end
IOS零碎技术整理(3)-获取wifi列表的更多相关文章
- IOS零碎技术整理(1)-后台运行
这两天做关于离线通知的功能,总结了一点关于这方面的注意点:按Home键回到桌面后程序很快被挂起,系统将关闭程序的Socket监听,此时程序将不能继续执行网络请求等操作. 两种方式可以使程序继续存活一段 ...
- IOS零碎技术整理(2)-隐藏系统Tabbar
原理就是将tabbar移出显示区 -(void)hideSystemTabBar:(UITabBar*) tabbarcontroller { [UIView beginAnimations:nil ...
- android 获取wifi列表,如果你忽略了这个细节,可能你的软件会崩溃
一:业务描述 最近公司有一个小需求,用户点击wifi扫描按钮(注意:是用户主动点击wifi扫描按钮),app去扫描附近的wifi,显示在listView中,仅此而已,app都不用去连接某个wifi,看 ...
- android开发-获取wifi列表
近期博主在学frangment框架,因此想着想着就想通过listfragment完毕对wifi列表的获取. 好! 如今就不说废话了. 一.wifi的基础知识 在Android的官方文档中定义了例如以下 ...
- iOS - 音乐播放器之怎么获取音乐列表
方法一: 这个方法是通过获取到沙盒路径,来得到音乐的路径(使用这个方法需要把音乐放进沙盒) NSFileManager *manager = [NSFileManager defaultManager ...
- iPhone,iPad如何获取WIFI名称即SSID
本文转载至 http://blog.csdn.net/wbw1985/article/details/20530281 2010年开始苹果清理了一批APP Store上的WIFI扫描软件, 缘由语焉 ...
- iOS 12中获取WiFi的SSID
开始搞智能家居,wifi获取不到了?? 小插曲 旧方法失效,19-12-15更新,ios13开始需要请求定位信息 SSID全称Service Set IDentifier, 即Wifi网络的公开名称. ...
- iOS开发中获取WiFi相关信息
iOS 开发中难免会遇到很多与网络方面的判断,这里做个汇总,大多可能是与WiFi相关的. 1.Ping域名.Ping某IP 有 时候可能会遇到ping 某个域名或者ip通不通,再做下一步操作.这里的p ...
- iOS - 什么!iOS13 又获取不到WiFi了
iOS 12 适配WiFi 增加隐私权限 https://www.cnblogs.com/baitongtong/p/10179519.html ios13又新增定位权限 别的不说,理解请看上篇文章 ...
随机推荐
- 【转】slice,substr和substring的区别
首先,他们都接收两个参数,slice和substring接收的是起始位置和结束位置(不包括结束位置),而substr接收的则是起始位置和所要返回的字符串长度.直接看下面例子: var test = ' ...
- NOIP 考前 计算几何练习
BZOJ 1580 直接解析算出每段的时间然后模拟即可 #include <iostream> #include <cstdio> #include <cstring&g ...
- oracle 行转列、列转行
最近做数据处理,经常遇到需要行转列.列转行的场景,记录个非常简单实用的oracle 列转行.行转的列方法 1.行转列,基础数据如下 做行转列处理 处理SQL select user_name,max ...
- matlab mesh visualization
1. matlab color specification http://au.mathworks.com/help/matlab/ref/colorspec.html
- CGAL4.1在VS2010上配置
配这个环境花了好几天的时间,虽然网上有很多相关的步骤,但是还是出了不少小错误,具体的步骤有很多,我就只记下我遇到的问题,我用的是CGAL4.1 boost1.51 CMake2.8 Qt4.8.2: ...
- SDK截图程序(一)
程序将系统窗口左上角100*100的图像复制到粘贴板上.程序的关键位置上加上了注释,相关知识<windows程序设计>第14章内容 #include <windows.h> # ...
- javaEE-----org.springframework.dao.InvalidDataAccessApiUsageException: Write operation
org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read ...
- Python 基礎 - 列表的使用
如果想要存所有 Marvel's The Avengers 角色的人名,該如何存呢?請用目前已學到的知識來實做- #!/usr/bin/env python3 # -*- coding:utf-8 - ...
- VLOOKUP
vlookup(查找目标,查找范围, 返回值的列数,精确或模糊查找) 1. 查找目标:查找的内容或者单元格引用. 2. 查找范围: 选定一个查找区域. 注意一: 查找目标一定要在该区域的第一列. 注意 ...
- 在Visual Lisp中处理自动化错误
Handling Automation errors in Visual LISP 翻译自原文Kean's blog:http://through-the-interface.typepad.com/ ...