获取wifi信息兼容iOS 14以上设备
This commit is contained in:
@@ -76,25 +76,14 @@ Copy NSString *wifiName;//当前wifi名称
|
||||
//
|
||||
// self.navigationItem.leftBarButtonItem=backItem;
|
||||
|
||||
NSDictionary *wifiDic = [self fetchSSIDInfo];
|
||||
NSString *wifiName = [wifiDic objectForKey:@"SSID"];
|
||||
self.wifiNameTextField.text = wifiName;
|
||||
[CommonUtils getNetworkTypeComplete:^(NSString *netconnType, NSString *BSSID, NSString *SSID) {
|
||||
self.wifiNameTextField.text = SSID;
|
||||
}];
|
||||
|
||||
}
|
||||
//获取当前链接WiFi信息
|
||||
- (id)fetchSSIDInfo
|
||||
{
|
||||
NSArray *ifs = (id)CFBridgingRelease(CNCopySupportedInterfaces());
|
||||
NSLog(@"%s: Supported interfaces: %@", __func__, ifs);
|
||||
id info = nil;
|
||||
for (NSString *ifnam in ifs) {
|
||||
info = (id)CFBridgingRelease(CNCopyCurrentNetworkInfo((CFStringRef)ifnam));
|
||||
if (info && [info count]) {
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
return info ;
|
||||
}
|
||||
|
||||
|
||||
-(void)clickBack{
|
||||
[self.navigationController popViewControllerAnimated:YES];
|
||||
}
|
||||
@@ -154,39 +143,30 @@ Copy NSString *wifiName;//当前wifi名称
|
||||
return YES;
|
||||
}
|
||||
- (IBAction)setLinkBtnClicked:(id)sender {
|
||||
if (self.nameLbl.text.length == 0) {
|
||||
[self.view makeToast:@"请输入正确的路由器名称"];
|
||||
return;
|
||||
}
|
||||
BOOL isRight =[dataContorl isIncludeSpecialCharact:self.pwdTf.text];
|
||||
|
||||
if (!isRight) {
|
||||
[self.view makeToast:@"您输入的密码带特殊符号,请更改路由器密码。"];
|
||||
return;
|
||||
}
|
||||
|
||||
if (![[self currentWifiSSID].lowercaseString hasPrefix:@"ifish"]) {
|
||||
[self.view makeToast:@"请先将手机连接到wifi:ifish-xxxx"];
|
||||
return;
|
||||
}
|
||||
|
||||
NSString *ssidName = self.nameLbl.text;
|
||||
NSString *ssidPwd = self.pwdTf.text;
|
||||
[self sendToDeviceWithSSIDName:ssidName andSSIDPWD:ssidPwd];
|
||||
[CommonUtils getNetworkTypeComplete:^(NSString *netconnType, NSString *BSSID, NSString *SSID) {
|
||||
if (self.nameLbl.text.length == 0) {
|
||||
[self.view makeToast:@"请输入正确的路由器名称"];
|
||||
return;
|
||||
}
|
||||
BOOL isRight =[dataContorl isIncludeSpecialCharact:self.pwdTf.text];
|
||||
|
||||
if (!isRight) {
|
||||
[self.view makeToast:@"您输入的密码带特殊符号,请更改路由器密码。"];
|
||||
return;
|
||||
}
|
||||
|
||||
if (![SSID.lowercaseString hasPrefix:@"ifish"]) {
|
||||
[self.view makeToast:@"请先将手机连接到wifi:ifish-xxxx"];
|
||||
return;
|
||||
}
|
||||
|
||||
NSString *ssidName = self.nameLbl.text;
|
||||
NSString *ssidPwd = self.pwdTf.text;
|
||||
[self sendToDeviceWithSSIDName:ssidName andSSIDPWD:ssidPwd];
|
||||
}];
|
||||
}
|
||||
|
||||
- (NSString *)currentWifiSSID {
|
||||
NSString *ssid = @"Not Found";
|
||||
CFArrayRef myArray = CNCopySupportedInterfaces();
|
||||
if (myArray != nil) {
|
||||
CFDictionaryRef myDict = CNCopyCurrentNetworkInfo(CFArrayGetValueAtIndex(myArray, 0));
|
||||
if (myDict != nil) {
|
||||
NSDictionary *dict = (NSDictionary *)CFBridgingRelease(myDict);
|
||||
ssid = [dict valueForKey:@"SSID"];
|
||||
}
|
||||
}
|
||||
return ssid;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - UDP related
|
||||
|
||||
@@ -213,31 +193,34 @@ Copy NSString *wifiName;//当前wifi名称
|
||||
}
|
||||
|
||||
- (void)startBinding {
|
||||
BOOL networkOk = NO;
|
||||
AFNetworkReachabilityStatus status = [AFNetworkReachabilityManager sharedManager].networkReachabilityStatus;
|
||||
if (status == AFNetworkReachabilityStatusReachableViaWiFi) {
|
||||
if (![[self currentWifiSSID].lowercaseString hasPrefix:@"ifish"]) {
|
||||
networkOk = YES;
|
||||
|
||||
[CommonUtils getNetworkTypeComplete:^(NSString *netconnType, NSString *BSSID, NSString *SSID) {
|
||||
if ([netconnType isEqualToString:@"no network"]||([netconnType isEqualToString:@"Wifi"]&&[SSID.lowercaseString hasPrefix:@"ifish"]))
|
||||
{
|
||||
|
||||
//无网络 或者连接的还是设备的热点
|
||||
}
|
||||
} else if (status == AFNetworkReachabilityStatusReachableViaWWAN) {
|
||||
networkOk = YES;
|
||||
}
|
||||
if (!networkOk) {
|
||||
return;
|
||||
}
|
||||
if (self.isBindingDevice) {
|
||||
return;
|
||||
}
|
||||
if (self.macAddress.length == 0) {
|
||||
return;
|
||||
}
|
||||
self.isBindingDevice = YES;
|
||||
if (self.bindTimer) {
|
||||
[self.bindTimer invalidate];
|
||||
self.bindTimer = nil;
|
||||
}
|
||||
self.retryTimes = 0;
|
||||
[self bindDeviceWithSsid:self.macAddress];
|
||||
else
|
||||
{
|
||||
if (self.isBindingDevice) {
|
||||
return;
|
||||
}
|
||||
if (self.macAddress.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
self.isBindingDevice = YES;
|
||||
if (self.bindTimer) {
|
||||
[self.bindTimer invalidate];
|
||||
self.bindTimer = nil;
|
||||
}
|
||||
self.retryTimes = 0;
|
||||
[self bindDeviceWithSsid:self.macAddress];
|
||||
|
||||
}
|
||||
}];
|
||||
|
||||
|
||||
}
|
||||
|
||||
- (void)udpHelperMessage:(NSString *)msg {
|
||||
|
||||
Reference in New Issue
Block a user