获取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];
|
||||
}
|
||||
|
||||
}
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
+13
-21
@@ -30,15 +30,18 @@
|
||||
}
|
||||
|
||||
- (IBAction)reset:(id)sender {
|
||||
if (![[self currentWifiSSID].lowercaseString hasPrefix:@"ifish"]) {
|
||||
[self.view makeToast:@"请先将手机连接到wifi:ifish-xxxx"];
|
||||
return;
|
||||
}
|
||||
self.HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
|
||||
self.HUD.mode = MBProgressHUDModeIndeterminate;
|
||||
self.HUD.labelText = @"重置指令已发出";
|
||||
[IFishHotpotUDPHelper sharedInstance].delegate = self;
|
||||
[[IFishHotpotUDPHelper sharedInstance] broadCastRestCommand];
|
||||
[CommonUtils getNetworkTypeComplete:^(NSString *netconnType, NSString *BSSID, NSString *SSID) {
|
||||
if (![SSID.lowercaseString hasPrefix:@"ifish"]) {
|
||||
[self.view makeToast:@"请先将手机连接到wifi:ifish-xxxx"];
|
||||
return;
|
||||
}
|
||||
self.HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
|
||||
self.HUD.mode = MBProgressHUDModeIndeterminate;
|
||||
self.HUD.labelText = @"重置指令已发出";
|
||||
[IFishHotpotUDPHelper sharedInstance].delegate = self;
|
||||
[[IFishHotpotUDPHelper sharedInstance] broadCastRestCommand];
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
- (IBAction)tipBtnClicked:(id)sender {
|
||||
@@ -62,17 +65,6 @@
|
||||
|
||||
#pragma mark - 删除设备
|
||||
|
||||
- (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;
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@
|
||||
// CFShow((__bridge CFTypeRef)(infoDic));
|
||||
NSString *app_Version=[infoDic objectForKey:@"CFBundleShortVersionString"];
|
||||
NSLog(@"app_Version%@",app_Version);
|
||||
app_Version=@"4.7.21";
|
||||
app_Version=@"4.7.22";
|
||||
NSString *versionStr = [NSString stringWithFormat:@"v%@",app_Version];
|
||||
NSString *buildVersion = [infoDic objectForKey:@"CFBundleVersion"];
|
||||
if (buildVersion.length > 0) {
|
||||
|
||||
+143
-151
@@ -125,21 +125,7 @@ typedef NS_ENUM(NSInteger,lodingViewdissMissStyle) {
|
||||
|
||||
}
|
||||
//获取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)viewWillDisappear:(BOOL)animated{
|
||||
[super viewWillDisappear:animated];
|
||||
@@ -164,123 +150,125 @@ typedef NS_ENUM(NSInteger,lodingViewdissMissStyle) {
|
||||
}
|
||||
-(void)initComponent{
|
||||
//967/1018/ 0.95
|
||||
|
||||
CGFloat percentHbiW = 0.117 ;//5s 35/300
|
||||
CGFloat y = 20;
|
||||
self.nodImg= [[UIImageView alloc] initWithFrame:CGRectMake(5, y,12, 12)];
|
||||
self.nodImg.image = [UIImage imageNamed:@"linkingdevice_point"];
|
||||
[self.view addSubview:self.nodImg];
|
||||
|
||||
|
||||
self.wifilabel=[[UILabel alloc] init];
|
||||
NSDictionary *ifs = [self fetchSSIDInfo];
|
||||
if (!self.wifiName.length)
|
||||
{
|
||||
self.wifiName = [ifs objectForKey:@"SSID"];
|
||||
}
|
||||
|
||||
|
||||
self.wifilabel.text = [NSString stringWithFormat:@"请输入当前WiFi:%@密码",self.wifiName];
|
||||
self.wifilabel.textAlignment = NSTextAlignmentLeft;
|
||||
|
||||
self.wifilabel.textColor = [UIColor colorWithRed:153.0/255.0 green:153.0/255.0 blue:153.0/255.0 alpha:1];
|
||||
NSMutableAttributedString * attributedString = [[NSMutableAttributedString alloc] initWithString:self.wifilabel.text];
|
||||
NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
|
||||
[paragraphStyle setLineSpacing:8];
|
||||
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [self.wifilabel.text length])];
|
||||
[attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:0 green:170.0/255.0 blue:218.0/255.0 alpha:1] range:NSMakeRange(10,self.wifiName.length)];
|
||||
[self.wifilabel setAttributedText:attributedString];
|
||||
[self.wifilabel sizeToFit];
|
||||
|
||||
CGFloat labelSizeW = [self widthForString:self.wifilabel.text fontSize:18 andHeight:10];
|
||||
CGFloat labelH= [self heightForString:self.wifilabel.text fontSize:18 andWidth:labelSizeW];
|
||||
|
||||
self.wifilabel.frame = CGRectMake(CGRectGetMaxX(self.nodImg.frame), y, labelSizeW, labelH);
|
||||
|
||||
[self.view addSubview:self.wifilabel];
|
||||
//wifi 输入框
|
||||
CGFloat wifiFileW=kScreenSize.width - 2*10;
|
||||
CGFloat wifiFileH=wifiFileW*percentHbiW;
|
||||
|
||||
self.wifiSecFiled=[[UITextField alloc] initWithFrame:CGRectMake(10,CGRectGetMaxY(self.wifilabel.frame) + 10, wifiFileW, wifiFileH)];
|
||||
|
||||
self.wifiSecFiled.placeholder = @"请输入WiFi密码";
|
||||
self.wifiSecFiled.delegate=self;
|
||||
self.wifiSecFiled.keyboardType=UIKeyboardTypeAlphabet;
|
||||
self.wifiSecFiled.layer.masksToBounds=YES;
|
||||
self.wifiSecFiled.layer.cornerRadius=5;
|
||||
if (@available(iOS 13.0, *)){//iOS13之后,设置颜色的方便变更
|
||||
[CommonUtils getNetworkTypeComplete:^(NSString *netconnType, NSString *BSSID, NSString *SSID) {
|
||||
CGFloat percentHbiW = 0.117 ;//5s 35/300
|
||||
CGFloat y = 20;
|
||||
self.nodImg= [[UIImageView alloc] initWithFrame:CGRectMake(5, y,12, 12)];
|
||||
self.nodImg.image = [UIImage imageNamed:@"linkingdevice_point"];
|
||||
[self.view addSubview:self.nodImg];
|
||||
|
||||
}else{
|
||||
[self.wifiSecFiled setValue:[UIColor colorWithRed:153.0/255.0 green:153.0/255.0 blue:153.0/255.0 alpha:1] forKeyPath:@"_placeholderLabel.textColor"];
|
||||
}
|
||||
self.wifiSecFiled.borderStyle = UITextBorderStyleNone;
|
||||
self.wifiSecFiled.backgroundColor = [UIColor colorWithRed:244.0/255.0 green:244.0/255.0 blue:244.0/255.0 alpha:1];
|
||||
NSUserDefaults*userDefsult=[NSUserDefaults standardUserDefaults];
|
||||
NSString*pass=[userDefsult objectForKey:@"wifiPass"];
|
||||
|
||||
if (pass) {
|
||||
self.wifiSecFiled.text = pass;
|
||||
}
|
||||
self.wifiSecFiled.textAlignment = NSTextAlignmentLeft;
|
||||
|
||||
[self.view addSubview:self.wifiSecFiled];
|
||||
|
||||
//占位view 让输入框文字 偏移 也有别的方法 contentoffset
|
||||
UIView*phoneView=[[UIView alloc]initWithFrame:CGRectMake(0,0, 9, 10)];
|
||||
self.wifiSecFiled.leftView=phoneView;
|
||||
self.wifiSecFiled.leftViewMode=UITextFieldViewModeAlways;
|
||||
|
||||
CGFloat btnW=100;
|
||||
//输入框内白色2像素view
|
||||
UIView *whiteView=[[UIView alloc] initWithFrame:CGRectMake(wifiFileW - btnW -2, 0, 2, wifiFileH)];
|
||||
whiteView.backgroundColor = [UIColor whiteColor];
|
||||
|
||||
[self.wifiSecFiled addSubview:whiteView];
|
||||
|
||||
|
||||
self.sBtn=[UIButton buttonWithType:UIButtonTypeCustom];
|
||||
[self.sBtn setTitle:@"确定" forState:UIControlStateNormal];
|
||||
|
||||
self.wifilabel=[[UILabel alloc] init];
|
||||
|
||||
if (!self.wifiName.length)
|
||||
{
|
||||
self.wifiName = SSID;
|
||||
}
|
||||
|
||||
|
||||
self.wifilabel.text = [NSString stringWithFormat:@"请输入当前WiFi:%@密码",self.wifiName];
|
||||
self.wifilabel.textAlignment = NSTextAlignmentLeft;
|
||||
|
||||
self.wifilabel.textColor = [UIColor colorWithRed:153.0/255.0 green:153.0/255.0 blue:153.0/255.0 alpha:1];
|
||||
NSMutableAttributedString * attributedString = [[NSMutableAttributedString alloc] initWithString:self.wifilabel.text];
|
||||
NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
|
||||
[paragraphStyle setLineSpacing:8];
|
||||
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [self.wifilabel.text length])];
|
||||
[attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:0 green:170.0/255.0 blue:218.0/255.0 alpha:1] range:NSMakeRange(10,self.wifiName.length)];
|
||||
[self.wifilabel setAttributedText:attributedString];
|
||||
[self.wifilabel sizeToFit];
|
||||
|
||||
CGFloat labelSizeW = [self widthForString:self.wifilabel.text fontSize:18 andHeight:10];
|
||||
CGFloat labelH= [self heightForString:self.wifilabel.text fontSize:18 andWidth:labelSizeW];
|
||||
|
||||
self.wifilabel.frame = CGRectMake(CGRectGetMaxX(self.nodImg.frame), y, labelSizeW, labelH);
|
||||
|
||||
[self.view addSubview:self.wifilabel];
|
||||
//wifi 输入框
|
||||
CGFloat wifiFileW=kScreenSize.width - 2*10;
|
||||
CGFloat wifiFileH=wifiFileW*percentHbiW;
|
||||
|
||||
self.wifiSecFiled=[[UITextField alloc] initWithFrame:CGRectMake(10,CGRectGetMaxY(self.wifilabel.frame) + 10, wifiFileW, wifiFileH)];
|
||||
|
||||
self.wifiSecFiled.placeholder = @"请输入WiFi密码";
|
||||
self.wifiSecFiled.delegate=self;
|
||||
self.wifiSecFiled.keyboardType=UIKeyboardTypeAlphabet;
|
||||
self.wifiSecFiled.layer.masksToBounds=YES;
|
||||
self.wifiSecFiled.layer.cornerRadius=5;
|
||||
if (@available(iOS 13.0, *)){//iOS13之后,设置颜色的方便变更
|
||||
|
||||
}else{
|
||||
[self.wifiSecFiled setValue:[UIColor colorWithRed:153.0/255.0 green:153.0/255.0 blue:153.0/255.0 alpha:1] forKeyPath:@"_placeholderLabel.textColor"];
|
||||
}
|
||||
self.wifiSecFiled.borderStyle = UITextBorderStyleNone;
|
||||
self.wifiSecFiled.backgroundColor = [UIColor colorWithRed:244.0/255.0 green:244.0/255.0 blue:244.0/255.0 alpha:1];
|
||||
NSUserDefaults*userDefsult=[NSUserDefaults standardUserDefaults];
|
||||
NSString*pass=[userDefsult objectForKey:@"wifiPass"];
|
||||
|
||||
if (pass) {
|
||||
self.wifiSecFiled.text = pass;
|
||||
}
|
||||
self.wifiSecFiled.textAlignment = NSTextAlignmentLeft;
|
||||
|
||||
[self.view addSubview:self.wifiSecFiled];
|
||||
|
||||
//占位view 让输入框文字 偏移 也有别的方法 contentoffset
|
||||
UIView*phoneView=[[UIView alloc]initWithFrame:CGRectMake(0,0, 9, 10)];
|
||||
self.wifiSecFiled.leftView=phoneView;
|
||||
self.wifiSecFiled.leftViewMode=UITextFieldViewModeAlways;
|
||||
|
||||
CGFloat btnW=100;
|
||||
//输入框内白色2像素view
|
||||
UIView *whiteView=[[UIView alloc] initWithFrame:CGRectMake(wifiFileW - btnW -2, 0, 2, wifiFileH)];
|
||||
whiteView.backgroundColor = [UIColor whiteColor];
|
||||
|
||||
[self.wifiSecFiled addSubview:whiteView];
|
||||
|
||||
|
||||
self.sBtn=[UIButton buttonWithType:UIButtonTypeCustom];
|
||||
[self.sBtn setTitle:@"确定" forState:UIControlStateNormal];
|
||||
|
||||
self.sBtn.frame = CGRectMake(wifiFileW - btnW,0, btnW,wifiFileH);
|
||||
|
||||
[self.sBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
||||
[self.sBtn addTarget:self action:@selector(sBtn:) forControlEvents:UIControlEventTouchUpInside];
|
||||
//self.sBtn.backgroundColor = COLOR_LABEL_TITLE;
|
||||
[self.sBtn setBackgroundImage:[UIImage imageNamed:@"linkingdevice_botton"] forState:UIControlStateNormal];
|
||||
[self.wifiSecFiled addSubview:self.sBtn];
|
||||
|
||||
//底部背景
|
||||
UIImageView *backImg=[[UIImageView alloc] initWithFrame:CGRectMake(0,kScreenSize.height - kScreenSize.width * 1.1,kScreenSize.width,kScreenSize.width * 1.1)];
|
||||
backImg.image = [UIImage imageNamed:@"linkingdevice_setting"];
|
||||
backImg.userInteractionEnabled = YES;
|
||||
|
||||
[self.view addSubview:backImg];
|
||||
self.sBtn.frame = CGRectMake(wifiFileW - btnW,0, btnW,wifiFileH);
|
||||
|
||||
[self.sBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
||||
[self.sBtn addTarget:self action:@selector(sBtn:) forControlEvents:UIControlEventTouchUpInside];
|
||||
//self.sBtn.backgroundColor = COLOR_LABEL_TITLE;
|
||||
[self.sBtn setBackgroundImage:[UIImage imageNamed:@"linkingdevice_botton"] forState:UIControlStateNormal];
|
||||
[self.wifiSecFiled addSubview:self.sBtn];
|
||||
|
||||
//底部背景
|
||||
UIImageView *backImg=[[UIImageView alloc] initWithFrame:CGRectMake(0,kScreenSize.height - kScreenSize.width * 1.1,kScreenSize.width,kScreenSize.width * 1.1)];
|
||||
backImg.image = [UIImage imageNamed:@"linkingdevice_setting"];
|
||||
backImg.userInteractionEnabled = YES;
|
||||
|
||||
[self.view addSubview:backImg];
|
||||
|
||||
|
||||
//波纹
|
||||
self.waveProgressView = [[LXWaveProgressView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.wifiSecFiled.frame) +10, kScreenSize.width,CGRectGetMinY(backImg.frame) - CGRectGetMaxY(self.wifiSecFiled.frame))];
|
||||
|
||||
self.attentionLabel=[[UILabel alloc]initWithFrame:CGRectMake(30, CGRectGetMidY(self.waveProgressView.frame), kScreenWidth-60, 130)];
|
||||
self.attentionLabel.font=[UIFont systemFontOfSize:13];
|
||||
self.attentionLabel.textColor=[UIColor blackColor];
|
||||
self.attentionLabel.numberOfLines=0;
|
||||
self.attentionLabel.text=@"1、请长按摄像头背后复位孔,复位摄像头。\n2、若Wifi名称有中文,请改成英文字母加数字。\n3、Wifi密码不能包含特殊符号(如‘“等)。\n4、若多次智能连接未成功,请尝试热点模式连接。";
|
||||
[self.view addSubview:self.waveProgressView];
|
||||
[self.view bringSubviewToFront:self.waveProgressView];
|
||||
[self.view addSubview:self.attentionLabel];
|
||||
|
||||
|
||||
|
||||
//说明书
|
||||
UIButton *shuimingshuBtn=[UIButton buttonWithType:UIButtonTypeCustom];
|
||||
shuimingshuBtn.frame = CGRectMake(0,kScreenSize.height - 44 - 200, kScreenSize.width*1/3, 200);
|
||||
[shuimingshuBtn addTarget:self action:@selector(ChaKanShuimingShu) forControlEvents:UIControlEventTouchUpInside];
|
||||
//[shuimingshuBtn setBackgroundColor:[UIColor redColor]];
|
||||
[self.view addSubview:shuimingshuBtn];
|
||||
|
||||
//设置输入状态UI
|
||||
[self connectNormalView];
|
||||
|
||||
//波纹
|
||||
self.waveProgressView = [[LXWaveProgressView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.wifiSecFiled.frame) +10, kScreenSize.width,CGRectGetMinY(backImg.frame) - CGRectGetMaxY(self.wifiSecFiled.frame))];
|
||||
|
||||
self.attentionLabel=[[UILabel alloc]initWithFrame:CGRectMake(30, CGRectGetMidY(self.waveProgressView.frame), kScreenWidth-60, 130)];
|
||||
self.attentionLabel.font=[UIFont systemFontOfSize:13];
|
||||
self.attentionLabel.textColor=[UIColor blackColor];
|
||||
self.attentionLabel.numberOfLines=0;
|
||||
self.attentionLabel.text=@"1、请长按摄像头背后复位孔,复位摄像头。\n2、若Wifi名称有中文,请改成英文字母加数字。\n3、Wifi密码不能包含特殊符号(如‘“等)。\n4、若多次智能连接未成功,请尝试热点模式连接。";
|
||||
[self.view addSubview:self.waveProgressView];
|
||||
[self.view bringSubviewToFront:self.waveProgressView];
|
||||
[self.view addSubview:self.attentionLabel];
|
||||
|
||||
|
||||
|
||||
//说明书
|
||||
UIButton *shuimingshuBtn=[UIButton buttonWithType:UIButtonTypeCustom];
|
||||
shuimingshuBtn.frame = CGRectMake(0,kScreenSize.height - 44 - 200, kScreenSize.width*1/3, 200);
|
||||
[shuimingshuBtn addTarget:self action:@selector(ChaKanShuimingShu) forControlEvents:UIControlEventTouchUpInside];
|
||||
//[shuimingshuBtn setBackgroundColor:[UIColor redColor]];
|
||||
[self.view addSubview:shuimingshuBtn];
|
||||
|
||||
//设置输入状态UI
|
||||
[self connectNormalView];
|
||||
|
||||
}];
|
||||
|
||||
|
||||
}
|
||||
@@ -315,14 +303,16 @@ self.attentionLabel.text=@"1、请长按摄像头背后复位孔,复位摄像
|
||||
#pragma mark- 点击确定
|
||||
-(void)goAPmode
|
||||
{
|
||||
ConAquarNowWiFiPwdVC *vc = InitObject(ConAquarNowWiFiPwdVC);
|
||||
vc.deviceType=DEVICECAMERA;
|
||||
NSDictionary *netInfo = [CommonUtils getSSIDInfo];
|
||||
vc.ssid = [netInfo objectForKey:@"SSID"];
|
||||
vc.bssid = [netInfo objectForKey:@"BSSID"];
|
||||
|
||||
|
||||
[self.navigationController pushViewController:vc animated:YES];
|
||||
[CommonUtils getNetworkTypeComplete:^(NSString *netconnType, NSString *BSSID, NSString *SSID) {
|
||||
ConAquarNowWiFiPwdVC *vc = InitObject(ConAquarNowWiFiPwdVC);
|
||||
vc.deviceType=DEVICECAMERA;
|
||||
|
||||
vc.ssid = SSID;
|
||||
vc.bssid = BSSID;
|
||||
|
||||
|
||||
[self.navigationController pushViewController:vc animated:YES];
|
||||
}];
|
||||
}
|
||||
-(void)sBtn:(UIButton*)btn{
|
||||
NSString *ssidName =@"";
|
||||
@@ -519,21 +509,23 @@ self.attentionLabel.text=@"1、请长按摄像头背后复位孔,复位摄像
|
||||
{
|
||||
//
|
||||
if (self.deviceID.length&&![self.linkDict[self.deviceID] boolValue]) {//90秒之后还未连接上,连接超时
|
||||
[[GWP2PDeviceLinker shareInstance] p2pStopSmartLink];
|
||||
[[GWP2PDeviceLinker shareInstance] p2pStopAPLink];
|
||||
|
||||
if ([[[CommonUtils getSSIDInfo] objectForKey:@"SSID"] isEqualToString:self.wifiName])
|
||||
{
|
||||
[self.view makeToast:@"请确保Wifi密码正确,重置设备后再试!"];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self.view makeToast:[NSString stringWithFormat:@"WiFi连接失败,请确保手机连接到%@",self.wifiName]];
|
||||
}
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
[CommonUtils getNetworkTypeComplete:^(NSString *netconnType, NSString *BSSID, NSString *SSID) {
|
||||
[[GWP2PDeviceLinker shareInstance] p2pStopSmartLink];
|
||||
[[GWP2PDeviceLinker shareInstance] p2pStopAPLink];
|
||||
|
||||
[self.navigationController popViewControllerAnimated:YES];
|
||||
});
|
||||
if ([SSID isEqualToString:self.wifiName])
|
||||
{
|
||||
[self.view makeToast:@"请确保Wifi密码正确,重置设备后再试!"];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self.view makeToast:[NSString stringWithFormat:@"WiFi连接失败,请确保手机连接到%@",self.wifiName]];
|
||||
}
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
|
||||
[self.navigationController popViewControllerAnimated:YES];
|
||||
});
|
||||
}];
|
||||
|
||||
}
|
||||
else if(!self.deviceID.length)
|
||||
|
||||
+2
-3
@@ -13,7 +13,7 @@
|
||||
#import "AppDelegate.h"
|
||||
#import "Utils.h"
|
||||
#import "UDManager.h"
|
||||
|
||||
#import "Reachability.h"
|
||||
#include <sys/types.h>
|
||||
#include <stdint.h>
|
||||
#include <unistd.h>
|
||||
@@ -161,8 +161,7 @@ withFilterContext:(id)filterContext
|
||||
while (1)
|
||||
{
|
||||
//没有连接wifi,肯定不是ap模式
|
||||
NSString* ssid = [Utils currentWifiSSID];
|
||||
if (ssid == nil) {
|
||||
if ([Reachability reachabilityForInternetConnection].currentReachabilityStatus!=ReachableViaWiFi) {
|
||||
NSLog(@"get ap mode info failed, no wifi");
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@
|
||||
while (1)
|
||||
{
|
||||
//没有wifi时不搜索
|
||||
NSString* ssid = [Utils currentWifiSSID];
|
||||
BOOL iswifi = ([Reachability reachabilityForInternetConnection].currentReachabilityStatus==ReachableViaWiFi);
|
||||
|
||||
//ap模式不搜索
|
||||
int dwApContactID = [[AppDelegate sharedDefault] dwApContactID];
|
||||
@@ -125,7 +125,7 @@
|
||||
//后台运行不搜索
|
||||
UIApplicationState iState = [UIApplication sharedApplication].applicationState;
|
||||
|
||||
_isConditionOK = (ssid != nil &&
|
||||
_isConditionOK = (iswifi &&
|
||||
dwApContactID == 0 &&
|
||||
iState != UIApplicationStateBackground);
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -245,31 +245,33 @@ extern BOOL formLogIn;//连接页面是否来自登录界面
|
||||
}];
|
||||
}
|
||||
-(void)connectMyWIFI{
|
||||
|
||||
NSUserDefaults*userDefsult=[NSUserDefaults standardUserDefaults];
|
||||
NSString*pass=[userDefsult objectForKey:@"wifiPass"];
|
||||
NSDictionary *netInfo = [self fetchNetInfo];
|
||||
_ssid = [netInfo objectForKey:@"SSID"];
|
||||
_bssid = [netInfo objectForKey:@"BSSID"];
|
||||
NSString *msg = [NSString stringWithFormat:@"请输入%@密码",_ssid];
|
||||
UIAlertView *alerV = [[UIAlertView alloc]initWithTitle:msg
|
||||
message:nil
|
||||
delegate:self
|
||||
cancelButtonTitle:@"取消"
|
||||
otherButtonTitles:@"确定", nil];
|
||||
alerV.alertViewStyle = UIAlertViewStylePlainTextInput;
|
||||
_wifiFiled=[alerV textFieldAtIndex:0];
|
||||
_wifiFiled.secureTextEntry=NO;
|
||||
_wifiFiled.text=pass;
|
||||
_wifiFiled.clearButtonMode=UITextFieldViewModeAlways;
|
||||
alerV.tag=ALERTVIEW_TAG;
|
||||
|
||||
[alerV show];
|
||||
|
||||
// [self bindDeviceWithSsid:@"5CCF7F0065CA"];
|
||||
// 5CCF7F00669C
|
||||
// 5CCF7F006668
|
||||
// 5CCF7F0065CA
|
||||
[CommonUtils getNetworkTypeComplete:^(NSString *netconnType, NSString *BSSID, NSString *SSID) {
|
||||
NSUserDefaults*userDefsult=[NSUserDefaults standardUserDefaults];
|
||||
NSString*pass=[userDefsult objectForKey:@"wifiPass"];
|
||||
|
||||
_ssid = SSID;
|
||||
_bssid = BSSID;
|
||||
NSString *msg = [NSString stringWithFormat:@"请输入%@密码",_ssid];
|
||||
UIAlertView *alerV = [[UIAlertView alloc]initWithTitle:msg
|
||||
message:nil
|
||||
delegate:self
|
||||
cancelButtonTitle:@"取消"
|
||||
otherButtonTitles:@"确定", nil];
|
||||
alerV.alertViewStyle = UIAlertViewStylePlainTextInput;
|
||||
_wifiFiled=[alerV textFieldAtIndex:0];
|
||||
_wifiFiled.secureTextEntry=NO;
|
||||
_wifiFiled.text=pass;
|
||||
_wifiFiled.clearButtonMode=UITextFieldViewModeAlways;
|
||||
alerV.tag=ALERTVIEW_TAG;
|
||||
|
||||
[alerV show];
|
||||
|
||||
// [self bindDeviceWithSsid:@"5CCF7F0065CA"];
|
||||
// 5CCF7F00669C
|
||||
// 5CCF7F006668
|
||||
// 5CCF7F0065CA
|
||||
|
||||
}];
|
||||
|
||||
}
|
||||
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
|
||||
@@ -395,39 +397,12 @@ extern BOOL formLogIn;//连接页面是否来自登录界面
|
||||
[userdefult synchronize];
|
||||
}
|
||||
|
||||
- (NSString *)fetchSsid
|
||||
{
|
||||
NSDictionary *ssidInfo = [self fetchNetInfo];
|
||||
|
||||
return [ssidInfo objectForKey:@"SSID"];
|
||||
}
|
||||
|
||||
- (NSString *)fetchBssid
|
||||
{
|
||||
NSDictionary *bssidInfo = [self fetchNetInfo];
|
||||
|
||||
return [bssidInfo objectForKey:@"BSSID"];
|
||||
}
|
||||
|
||||
|
||||
// refer to http://stackoverflow.com/questions/5198716/iphone-get-ssid-without-private-library
|
||||
- (NSDictionary *)fetchNetInfo
|
||||
{
|
||||
NSArray *interfaceNames = CFBridgingRelease(CNCopySupportedInterfaces());
|
||||
// NSLog(@"%s: Supported interfaces: %@", __func__, interfaceNames);
|
||||
|
||||
NSDictionary *SSIDInfo;
|
||||
for (NSString *interfaceName in interfaceNames) {
|
||||
SSIDInfo = CFBridgingRelease(
|
||||
CNCopyCurrentNetworkInfo((__bridge CFStringRef)interfaceName));
|
||||
// NSLog(@"%s: %@ => %@", __func__, interfaceName, SSIDInfo);
|
||||
|
||||
BOOL isNotEmpty = (SSIDInfo.count > 0);
|
||||
if (isNotEmpty) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return SSIDInfo;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark 绑定设备
|
||||
-(void)bindDeviceWithSsid:(NSString*)bssid{
|
||||
|
||||
|
||||
@@ -492,33 +492,35 @@ extern BOOL isfromCameraView;
|
||||
|
||||
}
|
||||
-(void)connectMyWIFI{
|
||||
|
||||
NSUserDefaults*userDefsult=[NSUserDefaults standardUserDefaults];
|
||||
NSString*pass=[userDefsult objectForKey:@"wifiPass"];
|
||||
NSDictionary *netInfo = [self fetchNetInfo];
|
||||
_ssid = [netInfo objectForKey:@"SSID"];
|
||||
_bssid = [netInfo objectForKey:@"BSSID"];
|
||||
|
||||
NSString *msg = [NSString stringWithFormat:@"请输入当前WiFi:%@的密码",_ssid];
|
||||
|
||||
NSMutableAttributedString * attributedString = [[NSMutableAttributedString alloc] initWithString:msg];
|
||||
[CommonUtils getNetworkTypeComplete:^(NSString *netconnType, NSString *BSSID, NSString *SSID) {
|
||||
|
||||
NSUserDefaults*userDefsult=[NSUserDefaults standardUserDefaults];
|
||||
NSString*pass=[userDefsult objectForKey:@"wifiPass"];
|
||||
|
||||
_ssid = SSID;
|
||||
_bssid = BSSID;
|
||||
|
||||
NSString *msg = [NSString stringWithFormat:@"请输入当前WiFi:%@的密码",_ssid];
|
||||
|
||||
NSMutableAttributedString * attributedString = [[NSMutableAttributedString alloc] initWithString:msg];
|
||||
|
||||
NSMutableParagraphStyle *paraghStyle =[[NSMutableParagraphStyle alloc] init];
|
||||
[paraghStyle setLineSpacing:4];
|
||||
[attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:0 green:170.0/255.0 blue:218.0/255.0 alpha:1] range:NSMakeRange(msg.length - 3 -_ssid.length,_ssid.length)];
|
||||
[attributedString addAttribute:NSParagraphStyleAttributeName value:paraghStyle range:NSMakeRange(0, msg.length)];
|
||||
|
||||
[_wifiNamelabel setAttributedText:attributedString];
|
||||
_wifiTextFiled.secureTextEntry=NO;
|
||||
_wifiTextFiled.text=pass;
|
||||
_wifiTextFiled.clearButtonMode=UITextFieldViewModeAlways;
|
||||
|
||||
|
||||
//[self bindDeviceWithSsid:@"5ccf7f003a93"];
|
||||
// 5CCF7F00669C
|
||||
// 5CCF7F006668
|
||||
// 5CCF7F0065CA
|
||||
|
||||
NSMutableParagraphStyle *paraghStyle =[[NSMutableParagraphStyle alloc] init];
|
||||
[paraghStyle setLineSpacing:4];
|
||||
[attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:0 green:170.0/255.0 blue:218.0/255.0 alpha:1] range:NSMakeRange(msg.length - 3 -_ssid.length,_ssid.length)];
|
||||
[attributedString addAttribute:NSParagraphStyleAttributeName value:paraghStyle range:NSMakeRange(0, msg.length)];
|
||||
|
||||
[_wifiNamelabel setAttributedText:attributedString];
|
||||
_wifiTextFiled.secureTextEntry=NO;
|
||||
_wifiTextFiled.text=pass;
|
||||
_wifiTextFiled.clearButtonMode=UITextFieldViewModeAlways;
|
||||
|
||||
|
||||
//[self bindDeviceWithSsid:@"5ccf7f003a93"];
|
||||
// 5CCF7F00669C
|
||||
// 5CCF7F006668
|
||||
// 5CCF7F0065CA
|
||||
|
||||
}];
|
||||
}
|
||||
-(void)checkLocation{
|
||||
NSString* phoneVersion = [[UIDevice currentDevice] systemVersion];
|
||||
@@ -530,24 +532,7 @@ extern BOOL isfromCameraView;
|
||||
}
|
||||
}
|
||||
// refer to http://stackoverflow.com/questions/5198716/iphone-get-ssid-without-private-library
|
||||
- (NSDictionary *)fetchNetInfo
|
||||
{
|
||||
NSArray *interfaceNames = CFBridgingRelease(CNCopySupportedInterfaces());
|
||||
// NSLog(@"%s: Supported interfaces: %@", __func__, interfaceNames);
|
||||
|
||||
NSDictionary *SSIDInfo;
|
||||
for (NSString *interfaceName in interfaceNames) {
|
||||
SSIDInfo = CFBridgingRelease(
|
||||
CNCopyCurrentNetworkInfo((__bridge CFStringRef)interfaceName));
|
||||
// NSLog(@"%s: %@ => %@", __func__, interfaceName, SSIDInfo);
|
||||
|
||||
BOOL isNotEmpty = (SSIDInfo.count > 0);
|
||||
if (isNotEmpty) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return SSIDInfo;
|
||||
}
|
||||
|
||||
|
||||
//保存wifi密码
|
||||
-(void)savePassw{
|
||||
|
||||
Reference in New Issue
Block a user