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列表的更多相关文章

  1. IOS零碎技术整理(1)-后台运行

    这两天做关于离线通知的功能,总结了一点关于这方面的注意点:按Home键回到桌面后程序很快被挂起,系统将关闭程序的Socket监听,此时程序将不能继续执行网络请求等操作. 两种方式可以使程序继续存活一段 ...

  2. IOS零碎技术整理(2)-隐藏系统Tabbar

    原理就是将tabbar移出显示区 -(void)hideSystemTabBar:(UITabBar*) tabbarcontroller { [UIView beginAnimations:nil ...

  3. android 获取wifi列表,如果你忽略了这个细节,可能你的软件会崩溃

    一:业务描述 最近公司有一个小需求,用户点击wifi扫描按钮(注意:是用户主动点击wifi扫描按钮),app去扫描附近的wifi,显示在listView中,仅此而已,app都不用去连接某个wifi,看 ...

  4. android开发-获取wifi列表

    近期博主在学frangment框架,因此想着想着就想通过listfragment完毕对wifi列表的获取. 好! 如今就不说废话了. 一.wifi的基础知识 在Android的官方文档中定义了例如以下 ...

  5. iOS - 音乐播放器之怎么获取音乐列表

    方法一: 这个方法是通过获取到沙盒路径,来得到音乐的路径(使用这个方法需要把音乐放进沙盒) NSFileManager *manager = [NSFileManager defaultManager ...

  6. iPhone,iPad如何获取WIFI名称即SSID

    本文转载至 http://blog.csdn.net/wbw1985/article/details/20530281  2010年开始苹果清理了一批APP Store上的WIFI扫描软件, 缘由语焉 ...

  7. iOS 12中获取WiFi的SSID

    开始搞智能家居,wifi获取不到了?? 小插曲 旧方法失效,19-12-15更新,ios13开始需要请求定位信息 SSID全称Service Set IDentifier, 即Wifi网络的公开名称. ...

  8. iOS开发中获取WiFi相关信息

    iOS 开发中难免会遇到很多与网络方面的判断,这里做个汇总,大多可能是与WiFi相关的. 1.Ping域名.Ping某IP 有 时候可能会遇到ping 某个域名或者ip通不通,再做下一步操作.这里的p ...

  9. iOS - 什么!iOS13 又获取不到WiFi了

    iOS 12 适配WiFi 增加隐私权限 https://www.cnblogs.com/baitongtong/p/10179519.html ios13又新增定位权限 别的不说,理解请看上篇文章 ...

随机推荐

  1. 【转】C#线程同步示例

    using System; using System.Threading; // 银行帐户类 class Account { int balance;                         ...

  2. iOS 创建framework & bundle 主要配置

    bundle:base sdk 为iOS, delete compile resource framework:target dependencies,headers,mach-o proj: tar ...

  3. Java(二)

    课后,我查阅相关学习资料和Java API制作了以下界面,界面包含了单选按钮(JRadioButton).复选框(JCheckBox).组合框(JComboBox).单行文本输入框(JTextFiel ...

  4. 对一个目录的文件从cp936转换成utf-8

    打开一个文件,确认能够无乱码打开 [xw@localhost work]$ vi NPOSP/src/sjl05.cpp 但是,这里打开的方式是以cp936的编码方式打开的. 编码的选择,记录在~/. ...

  5. 苹果Home键恢复(无工具篇)

    无工具法: 弹指神功.用手指轻轻弹Home,过了一阵子后可能会出现白色污垢,其后再重覆“弹”,直至正常为止.(亲测可用) 软件调试法.首先,打开任意一款应用程序,按住电源开关几秒钟,直到屏幕出现滑动关 ...

  6. git format-patch & git apply & git clean

    一.打补丁 git format-patch & git apply 最近在工作中遇到打补丁的需求,一来觉得直接传文件有些low(而且我尝试了一下,差点把项目代码毁了) ,二来也是想学习一下, ...

  7. hibernate persist update 方法没有正常工作(不保存数据,不更新数据)

    工程结构 问题描述 在工程中通过spring aop的方式配置事务,使用hibernate做持久化.在代码实现中使用hibernate persit()方法插入数据到数据库,使用hibernate u ...

  8. Vim速查脑图

  9. JavaScript中字符串去掉特殊字符和转义字符

    <pre name="code" class="javascript">/*** * 去掉字符串中的特殊字符 */ var excludeSpeci ...

  10. 新冲刺Sprint3(第六天)

    一.Sprint介绍 商家功能模块继续完善着,加快了工作的步伐. 二.Sprint周期 看板: 燃尽图: