由于苹果是闭源的,所以我们不能像安卓那样对一些东西进行操作,比如WIFI,通过使用一些私有的API并在越狱的iPhone上面或许你能够实现那些功能,但是这样做有很大的局限性:1.私有API苹果审核不会让你通过,2.现在很多iPhone用户都不再选择越狱,但是如果我们仅仅想要知道自己现在所连接的WiFi叫啥名我们还是可以通过苹果提供的共有API去实现的。这就要用到SystemConfiguration.framework这个框架了。废话不多说,直接上代码:
//导入框架头文件
#import<SystemConfiguration/CaptiveNetwork>
@interfaceViewController()
//定义一个label用于显示当前所连WiFi名称
@property(weak, nonatomic)IBOutletUILabel*l1;
@property(weak, nonatomic)IBOutletUILabel*l2;
@end
@implementationViewController
- (void)viewDidLoad {
[superviewDidLoad];
idinfo =nil;
NSArray*ifs = (__bridge_transferid)CNCopySupportedInterfaces();
for(NSString*ifnaminifs) {
info = (__bridge_transferid)CNCopyCurrentNetworkInfo((__bridgeCFStringRef)ifnam);
NSString*str = info[@"SSID"];
NSString*str2 = info[@"BSSID"];
NSString*str3 = [[NSStringalloc]initWithData:info[@"SSIDDATA"]encoding:NSUTF8StringEncoding];
_l1.text = str;
_l2.text = str2;
}
}
@end
跳转wifi界面
NSString * urlString = @"App-Prefs:root=WIFI";
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:urlString]]) {
if ([[[UIDevice currentDevice]systemVersion] floatValue]>=10) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{} completionHandler:nil];
} else {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=WIFI"]];
}