获取wifi信息兼容iOS 14以上设备
This commit is contained in:
@@ -117,57 +117,50 @@ Assign BOOL isGoChangeWiFi;//更换为设备的WiFi
|
||||
}
|
||||
}
|
||||
-(void)checkWiFi{
|
||||
NSDictionary *ifs = [self getSSIDInfo];
|
||||
NSString *wifiName = [ifs objectForKey:@"SSID"];
|
||||
//先判断之前的wifi名称是否和热点的wifi名称重复,如果冲突,则提示wifi名称错误
|
||||
if ([wifiName isEqualToString:self.wifiName]) {
|
||||
[self.view makeToast:@"请先连接设备热点"];
|
||||
return;
|
||||
}
|
||||
if ([wifiName rangeOfString:@"ifish"].location!=NSNotFound||[wifiName rangeOfString:@"GW"].location!=NSNotFound||[wifiName.lowercaseString isEqualToString:@"wlan"]||![wifiName isEqualToString:self.wifiName]) {
|
||||
//wifi正确,则尝试连接设备
|
||||
if(self.deviceType==DEVICECAMERA)
|
||||
{
|
||||
YooseeNextConnectViewController *nextvc=[[YooseeNextConnectViewController alloc] init];
|
||||
nextvc.wifiName=self.wifiName;
|
||||
nextvc.wifiPwd=self.wifiPwd;
|
||||
[CommonUtils getNetworkTypeComplete:^(NSString *netconnType, NSString *BSSID, NSString *SSID) {
|
||||
|
||||
NSString *wifiName = SSID;
|
||||
//先判断之前的wifi名称是否和热点的wifi名称重复,如果冲突,则提示wifi名称错误
|
||||
if ([wifiName isEqualToString:self.wifiName]) {
|
||||
[self.view makeToast:@"请先连接设备热点"];
|
||||
return;
|
||||
}
|
||||
if ([wifiName rangeOfString:@"ifish"].location!=NSNotFound||[wifiName rangeOfString:@"GW"].location!=NSNotFound) {
|
||||
//wifi正确,则尝试连接设备
|
||||
if(self.deviceType==DEVICECAMERA)
|
||||
{
|
||||
YooseeNextConnectViewController *nextvc=[[YooseeNextConnectViewController alloc] init];
|
||||
nextvc.wifiName=self.wifiName;
|
||||
nextvc.wifiPwd=self.wifiPwd;
|
||||
|
||||
nextvc.conectType =conectType_ap;
|
||||
[self.navigationController pushViewController:nextvc animated:YES];
|
||||
}
|
||||
else
|
||||
{
|
||||
ConnectingAquarVC *connecting = InitObject(ConnectingAquarVC);
|
||||
connecting.ssid = self.ssid;
|
||||
connecting.bssid = self.bssid;
|
||||
connecting.wifiName = self.wifiName;
|
||||
connecting.wifiPassword = self.wifiPwd;
|
||||
connecting.deviceType=self.deviceType;
|
||||
[self.navigationController pushViewController:connecting animated:YES];
|
||||
}
|
||||
|
||||
nextvc.conectType =conectType_ap;
|
||||
[self.navigationController pushViewController:nextvc animated:YES];
|
||||
}else{
|
||||
[self.view makeToast:@"WiFi名称不匹配,请重试"];
|
||||
}
|
||||
else
|
||||
{
|
||||
ConnectingAquarVC *connecting = InitObject(ConnectingAquarVC);
|
||||
connecting.ssid = self.ssid;
|
||||
connecting.bssid = self.bssid;
|
||||
connecting.wifiName = self.wifiName;
|
||||
connecting.wifiPassword = self.wifiPwd;
|
||||
connecting.deviceType=self.deviceType;
|
||||
[self.navigationController pushViewController:connecting animated:YES];
|
||||
}
|
||||
|
||||
}else{
|
||||
[self.view makeToast:@"WiFi名称不匹配,请重试"];
|
||||
}
|
||||
}
|
||||
- (NSDictionary *)getSSIDInfo
|
||||
{
|
||||
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;
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
//即将进入前台
|
||||
-(void)viewWillEnterForeground:(NSNotification *)noti{
|
||||
if (self.isGoChangeWiFi) {
|
||||
[self checkWiFi];
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.35 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
[self checkWiFi];
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
||||
@@ -143,14 +143,17 @@ Strong UILabel *subTitleLabel;
|
||||
|
||||
//热点链接
|
||||
}else{
|
||||
ConAquarNowWiFiPwdVC *vc = InitObject(ConAquarNowWiFiPwdVC);
|
||||
vc.deviceType=self.deviceType;
|
||||
NSDictionary *netInfo = [CommonUtils getSSIDInfo];
|
||||
vc.ssid = [netInfo objectForKey:@"SSID"];
|
||||
vc.bssid = [netInfo objectForKey:@"BSSID"];
|
||||
vc.deviceType=self.deviceType;
|
||||
[CommonUtils getNetworkTypeComplete:^(NSString *netconnType, NSString *BSSID, NSString *SSID) {
|
||||
ConAquarNowWiFiPwdVC *vc = InitObject(ConAquarNowWiFiPwdVC);
|
||||
vc.deviceType=self.deviceType;
|
||||
|
||||
vc.ssid = SSID;
|
||||
vc.bssid = BSSID;
|
||||
vc.deviceType=self.deviceType;
|
||||
|
||||
[self.navigationController pushViewController:vc animated:YES];
|
||||
}];
|
||||
|
||||
[self.navigationController pushViewController:vc animated:YES];
|
||||
}
|
||||
}
|
||||
- (UILabel *)subTitleLabel
|
||||
|
||||
@@ -200,31 +200,21 @@ Strong UIButton *nextBtn;
|
||||
}
|
||||
-(void)connectMyWIFI{
|
||||
|
||||
NSUserDefaults*userDefsult=[NSUserDefaults standardUserDefaults];
|
||||
NSString*pass=[userDefsult objectForKey:@"wifiPass"];
|
||||
NSDictionary *netInfo = [self getSSIDInfo];
|
||||
_ssid = [netInfo objectForKey:@"SSID"];
|
||||
_bssid = [netInfo objectForKey:@"BSSID"];
|
||||
[CommonUtils getNetworkTypeComplete:^(NSString *netconnType, NSString *BSSID, NSString *SSID) {
|
||||
NSUserDefaults*userDefsult=[NSUserDefaults standardUserDefaults];
|
||||
NSString*pass=[userDefsult objectForKey:@"wifiPass"];
|
||||
|
||||
_ssid = SSID;
|
||||
_bssid = BSSID;
|
||||
|
||||
self.wifiPwdTextField.text=pass;
|
||||
self.wifiNameTextField.text = [netInfo objectForKey:@"SSID"];
|
||||
self.wifiPwdTextField.text=pass;
|
||||
self.wifiNameTextField.text = SSID;
|
||||
|
||||
}];
|
||||
}
|
||||
// refer to http://stackoverflow.com/questions/5198716/iphone-get-ssid-without-private-library
|
||||
//获取WiFi信息
|
||||
- (NSDictionary *)getSSIDInfo
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark --buttonClick
|
||||
-(void)nextBtnClick:(UIButton *)sender{
|
||||
BOOL isRight =[dataContorl isIncludeSpecialCharact:self.wifiPwdTextField.text];
|
||||
|
||||
@@ -244,18 +244,7 @@ Copy NSString *deviceId;
|
||||
}
|
||||
#pragma mark - UDP related
|
||||
|
||||
- (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;
|
||||
}
|
||||
|
||||
|
||||
- (void)sendToDeviceWithSSIDName:(NSString *)name andSSIDPWD:(NSString *)pwd {
|
||||
[IFishHotpotUDPHelper sharedInstance].delegate = self;
|
||||
@@ -282,34 +271,34 @@ Copy NSString *deviceId;
|
||||
|
||||
- (void)startBinding {
|
||||
|
||||
BOOL networkOk = NO;
|
||||
AFNetworkReachabilityStatus status = [AFNetworkReachabilityManager sharedManager].networkReachabilityStatus;
|
||||
if (status == AFNetworkReachabilityStatusReachableViaWiFi||status == AFNetworkReachabilityStatusUnknown) {
|
||||
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.retryTimes = 0;
|
||||
if (self.deviceType==DEVICEPETS)
|
||||
{
|
||||
[self showStoreNameView];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self bindDeviceWithSsid:self.macAddress];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (self.isBindingDevice) {
|
||||
return;
|
||||
}
|
||||
if (self.macAddress.length == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
self.retryTimes = 0;
|
||||
if (self.deviceType==DEVICEPETS)
|
||||
{
|
||||
[self showStoreNameView];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self bindDeviceWithSsid:self.macAddress];
|
||||
}
|
||||
|
||||
}
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user