获取wifi信息兼容iOS 14以上设备

This commit is contained in:
kai60 2022-04-29 18:07:47 +08:00
parent 64d5967585
commit 27b8ee3653
16 changed files with 474 additions and 485 deletions

View File

@ -2292,6 +2292,7 @@
C0721974253C054D0065CF17 /* PlayBackViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = C0721971253C054D0065CF17 /* PlayBackViewController.xib */; }; C0721974253C054D0065CF17 /* PlayBackViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = C0721971253C054D0065CF17 /* PlayBackViewController.xib */; };
C0837A57244FF5510034FEC5 /* EGOCache.m in Sources */ = {isa = PBXBuildFile; fileRef = C0837A55244FF5500034FEC5 /* EGOCache.m */; }; C0837A57244FF5510034FEC5 /* EGOCache.m in Sources */ = {isa = PBXBuildFile; fileRef = C0837A55244FF5500034FEC5 /* EGOCache.m */; };
C0837A58244FF5510034FEC5 /* EGOCache.h in Headers */ = {isa = PBXBuildFile; fileRef = C0837A56244FF5500034FEC5 /* EGOCache.h */; }; C0837A58244FF5510034FEC5 /* EGOCache.h in Headers */ = {isa = PBXBuildFile; fileRef = C0837A56244FF5500034FEC5 /* EGOCache.h */; };
C089767E281BCB3A0098B5FA /* NetworkExtension.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C089767D281BCB3A0098B5FA /* NetworkExtension.framework */; };
C0B2F541244C6FE3001079AA /* PetStoresViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = C0B2F53E244C6FE3001079AA /* PetStoresViewController.h */; }; C0B2F541244C6FE3001079AA /* PetStoresViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = C0B2F53E244C6FE3001079AA /* PetStoresViewController.h */; };
C0B2F542244C6FE3001079AA /* PetStoresViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C0B2F53F244C6FE3001079AA /* PetStoresViewController.m */; }; C0B2F542244C6FE3001079AA /* PetStoresViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = C0B2F53F244C6FE3001079AA /* PetStoresViewController.m */; };
C0B2F543244C6FE3001079AA /* PetStoresViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = C0B2F540244C6FE3001079AA /* PetStoresViewController.xib */; }; C0B2F543244C6FE3001079AA /* PetStoresViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = C0B2F540244C6FE3001079AA /* PetStoresViewController.xib */; };
@ -5772,6 +5773,7 @@
C0721971253C054D0065CF17 /* PlayBackViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = PlayBackViewController.xib; sourceTree = "<group>"; }; C0721971253C054D0065CF17 /* PlayBackViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = PlayBackViewController.xib; sourceTree = "<group>"; };
C0837A55244FF5500034FEC5 /* EGOCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EGOCache.m; sourceTree = "<group>"; }; C0837A55244FF5500034FEC5 /* EGOCache.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EGOCache.m; sourceTree = "<group>"; };
C0837A56244FF5500034FEC5 /* EGOCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EGOCache.h; sourceTree = "<group>"; }; C0837A56244FF5500034FEC5 /* EGOCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EGOCache.h; sourceTree = "<group>"; };
C089767D281BCB3A0098B5FA /* NetworkExtension.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = NetworkExtension.framework; path = System/Library/Frameworks/NetworkExtension.framework; sourceTree = SDKROOT; };
C0B2F53E244C6FE3001079AA /* PetStoresViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PetStoresViewController.h; sourceTree = "<group>"; }; C0B2F53E244C6FE3001079AA /* PetStoresViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PetStoresViewController.h; sourceTree = "<group>"; };
C0B2F53F244C6FE3001079AA /* PetStoresViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PetStoresViewController.m; sourceTree = "<group>"; }; C0B2F53F244C6FE3001079AA /* PetStoresViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PetStoresViewController.m; sourceTree = "<group>"; };
C0B2F540244C6FE3001079AA /* PetStoresViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = PetStoresViewController.xib; sourceTree = "<group>"; }; C0B2F540244C6FE3001079AA /* PetStoresViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = PetStoresViewController.xib; sourceTree = "<group>"; };
@ -6154,6 +6156,7 @@
isa = PBXFrameworksBuildPhase; isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647; buildActionMask = 2147483647;
files = ( files = (
C089767E281BCB3A0098B5FA /* NetworkExtension.framework in Frameworks */,
CB484CF122B87D250075F050 /* libresolv.tbd in Frameworks */, CB484CF122B87D250075F050 /* libresolv.tbd in Frameworks */,
88C6861C1EA61000004CDFD9 /* libsqlite3.0.tbd in Frameworks */, 88C6861C1EA61000004CDFD9 /* libsqlite3.0.tbd in Frameworks */,
18C54F202350541500DF4E7D /* AlibabaAuthSDK.framework in Frameworks */, 18C54F202350541500DF4E7D /* AlibabaAuthSDK.framework in Frameworks */,
@ -12016,6 +12019,7 @@
88C686121EA60EA9004CDFD9 /* Frameworks */ = { 88C686121EA60EA9004CDFD9 /* Frameworks */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
C089767D281BCB3A0098B5FA /* NetworkExtension.framework */,
C0F0400B23756F3C00B61D3B /* ExternalAccessory.framework */, C0F0400B23756F3C00B61D3B /* ExternalAccessory.framework */,
CB484CEF22B8720D0075F050 /* GLKit.framework */, CB484CEF22B8720D0075F050 /* GLKit.framework */,
CB7D6AF52296A6FF0014E5C7 /* libresolv.tbd */, CB7D6AF52296A6FF0014E5C7 /* libresolv.tbd */,
@ -15869,7 +15873,7 @@
CODE_SIGN_IDENTITY = "iPhone Developer"; CODE_SIGN_IDENTITY = "iPhone Developer";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 4; CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = WFX8GD5HFX; DEVELOPMENT_TEAM = WFX8GD5HFX;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
ENABLE_TESTABILITY = YES; ENABLE_TESTABILITY = YES;
@ -15945,7 +15949,7 @@
"$(PROJECT_DIR)/Ifish/controllers/IfishYooseeFile/IfishYsooseeNewLib/libAVCtrlIOS/libAVCtrl", "$(PROJECT_DIR)/Ifish/controllers/IfishYooseeFile/IfishYsooseeNewLib/libAVCtrlIOS/libAVCtrl",
"$(PROJECT_DIR)/Ifish/controllers/IfishYooseeFile/IfishYsooseeNewLib/libAVCtrl", "$(PROJECT_DIR)/Ifish/controllers/IfishYooseeFile/IfishYsooseeNewLib/libAVCtrl",
); );
MARKETING_VERSION = 5.1.21; MARKETING_VERSION = 5.1.22;
ONLY_ACTIVE_ARCH = YES; ONLY_ACTIVE_ARCH = YES;
OTHER_LDFLAGS = ( OTHER_LDFLAGS = (
"-ObjC", "-ObjC",
@ -15988,7 +15992,7 @@
CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_IDENTITY = "Apple Development";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "Apple Development"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "Apple Development";
CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 4; CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = WFX8GD5HFX; DEVELOPMENT_TEAM = WFX8GD5HFX;
ENABLE_BITCODE = NO; ENABLE_BITCODE = NO;
ENABLE_TESTABILITY = YES; ENABLE_TESTABILITY = YES;
@ -16064,7 +16068,7 @@
"$(PROJECT_DIR)/Ifish/controllers/IfishYooseeFile/IfishYsooseeNewLib/libAVCtrlIOS/libAVCtrl", "$(PROJECT_DIR)/Ifish/controllers/IfishYooseeFile/IfishYsooseeNewLib/libAVCtrlIOS/libAVCtrl",
"$(PROJECT_DIR)/Ifish/controllers/IfishYooseeFile/IfishYsooseeNewLib/libAVCtrl", "$(PROJECT_DIR)/Ifish/controllers/IfishYooseeFile/IfishYsooseeNewLib/libAVCtrl",
); );
MARKETING_VERSION = 5.1.21; MARKETING_VERSION = 5.1.22;
ONLY_ACTIVE_ARCH = NO; ONLY_ACTIVE_ARCH = NO;
OTHER_LDFLAGS = ( OTHER_LDFLAGS = (
"-ObjC", "-ObjC",

View File

@ -337,9 +337,11 @@ if (kScreenSize.height>480) {
int ap3cid = [[ShakeManager sharedDefault] ApModeGetID]; int ap3cid = [[ShakeManager sharedDefault] ApModeGetID];
if (ap3cid != 0) if (ap3cid != 0)
{ {
self.dwApContactID = ap3cid; [CommonUtils getNetworkTypeComplete:^(NSString *netconnType, NSString *BSSID, NSString *SSID) {
self.sWifi = [Utils currentWifiSSID]; self.dwApContactID = ap3cid;
[[UDPManager sharedDefault] ScanLanDevice]; self.sWifi = SSID;
[[UDPManager sharedDefault] ScanLanDevice];
}];
return YES; return YES;
} }
else else

View File

@ -9,6 +9,9 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import "UIColor+HexString.h" #import "UIColor+HexString.h"
#import <SystemConfiguration/CaptiveNetwork.h> #import <SystemConfiguration/CaptiveNetwork.h>
#import <NetworkExtension/NetworkExtension.h>
#import "Reachability.h"
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
@interface CommonUtils : NSObject @interface CommonUtils : NSObject
typedef enum{ typedef enum{
@ -22,8 +25,6 @@ typedef enum{
//系统默认整体页面背景色 //系统默认整体页面背景色
#define COLOR_Background HEXCOLOR(@"#f6f6f6") #define COLOR_Background HEXCOLOR(@"#f6f6f6")
/// 获取WiFi信息
+ (NSDictionary *)getSSIDInfo;
/** /**
*/ */
@ -161,4 +162,5 @@ typedef enum{
CGAffineTransform GetCGAffineTransformRotateAroundPoint(float centerX, float centerY ,float x ,float y ,float angle); CGAffineTransform GetCGAffineTransformRotateAroundPoint(float centerX, float centerY ,float x ,float y ,float angle);
+ (void)interfaceOrientation:(UIInterfaceOrientation)orientation; + (void)interfaceOrientation:(UIInterfaceOrientation)orientation;
+ (UIBarButtonItem*)ItemWithTitle:(NSString *)title target:(id)target action:(SEL)action titleColor:(UIColor*)titleColor; + (UIBarButtonItem*)ItemWithTitle:(NSString *)title target:(id)target action:(SEL)action titleColor:(UIColor*)titleColor;
+ (void )getNetworkTypeComplete:(void(^)(NSString*netconnType,NSString *BSSID,NSString *SSID))complete;
@end @end

View File

@ -312,20 +312,7 @@
[button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside]; [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
return [[UIBarButtonItem alloc] initWithCustomView:button]; return [[UIBarButtonItem alloc] initWithCustomView:button];
} }
+ (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;
}
//view //view
CGAffineTransform GetCGAffineTransformRotateAroundPoint(float centerX, float centerY ,float x ,float y ,float angle) CGAffineTransform GetCGAffineTransformRotateAroundPoint(float centerX, float centerY ,float x ,float y ,float angle)
{ {
@ -745,4 +732,97 @@ if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
} }
return string; return string;
} }
+ (void )getNetworkTypeComplete:(void(^)(NSString*netconnType,NSString *BSSID,NSString *SSID))complete
{
NSString *netconnType = @"";
NSString *BSSID = @"";
NSString *SSID = @"";
switch ([[Reachability reachabilityForInternetConnection] currentReachabilityStatus])
{
case NotReachable://
{
netconnType = @"no network";
}
break;
case ReachableViaWiFi:// Wifi
{
netconnType = @"Wifi";
if (@available(iOS 14.0, *))
{
[NEHotspotNetwork fetchCurrentWithCompletionHandler:^(NEHotspotNetwork * _Nullable currentNetwork) {
if (complete) {
complete(netconnType,[CommonUtils standardFormateMAC:[CommonUtils getNotNilStr:currentNetwork.BSSID]],[CommonUtils getNotNilStr:currentNetwork.SSID]);
}
}];
return;
}
else
{
NSArray *ifs = (__bridge_transfer NSArray *)CNCopySupportedInterfaces();
NSDictionary *info = nil;
for (NSString *ifnam in ifs)
{
info = (__bridge_transfer NSDictionary *)CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam);
if (info && [info count]) break;
}
NSMutableDictionary *resultDic = [NSMutableDictionary dictionary];
for (NSString *key in info.allKeys)
{
NSObject *value = [info objectForKey:key];
if ([value isKindOfClass:NSString.class]) {
[resultDic setObject:value forKey:key];
}
}
BSSID=[CommonUtils getNotNilStr:[CommonUtils standardFormateMAC:resultDic[@"BSSID"]]];
SSID=[CommonUtils getNotNilStr:resultDic[@"SSID"]];
}
}
break;
case ReachableViaWWAN://
{ //
CTTelephonyNetworkInfo *info = [[CTTelephonyNetworkInfo alloc] init];
NSString *currentStatus = info.currentRadioAccessTechnology;
if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyGPRS"]) {
netconnType = @"GPRS";
}else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyCDMA1x"]){
netconnType = @"2G";
}else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyCDMAEVDORev0"] || [currentStatus isEqualToString:@"CTRadioAccessTechnologyCDMAEVDORevA"] || [currentStatus isEqualToString:@"CTRadioAccessTechnologyCDMAEVDORevB"] || [currentStatus isEqualToString:@"CTRadioAccessTechnologyWCDMA"]){
netconnType = @"3G";
}else if ([currentStatus isEqualToString:@"CTRadioAccessTechnologyLTE"]){
netconnType = @"4G";
}else{
netconnType = @"other";
}
}
break;
default:
break;
}
if (complete) {
complete(netconnType,BSSID,SSID);
}
}
+(NSString *)standardFormateMAC:(NSString *)MAC {
NSArray * subStr = [MAC componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@":-"]];
NSMutableArray * subStr_M = [[NSMutableArray alloc] initWithCapacity:0];
for (NSString * str in subStr) {
if (1 == str.length) {
NSString * tmpStr = [NSString stringWithFormat:@"0%@", str];
[subStr_M addObject:tmpStr];
} else {
[subStr_M addObject:str];
}
}
NSString * formateMAC = [subStr_M componentsJoinedByString:@":"];
return [formateMAC uppercaseString];
}
@end @end

View File

@ -117,57 +117,50 @@ Assign BOOL isGoChangeWiFi;//更换为设备的WiFi
} }
} }
-(void)checkWiFi{ -(void)checkWiFi{
NSDictionary *ifs = [self getSSIDInfo]; [CommonUtils getNetworkTypeComplete:^(NSString *netconnType, NSString *BSSID, NSString *SSID) {
NSString *wifiName = [ifs objectForKey:@"SSID"];
//wifiwifiwifi
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;
nextvc.conectType =conectType_ap; NSString *wifiName = SSID;
[self.navigationController pushViewController:nextvc animated:YES]; //wifiwifiwifi
} if ([wifiName isEqualToString:self.wifiName]) {
else [self.view makeToast:@"请先连接设备热点"];
{ return;
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];
} }
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;
}else{ nextvc.conectType =conectType_ap;
[self.view makeToast:@"WiFi名称不匹配请重试"]; [self.navigationController pushViewController:nextvc animated:YES];
} }
} else
- (NSDictionary *)getSSIDInfo {
{ ConnectingAquarVC *connecting = InitObject(ConnectingAquarVC);
NSArray *interfaceNames = CFBridgingRelease(CNCopySupportedInterfaces()); connecting.ssid = self.ssid;
NSDictionary *SSIDInfo; connecting.bssid = self.bssid;
for (NSString *interfaceName in interfaceNames) { connecting.wifiName = self.wifiName;
SSIDInfo = CFBridgingRelease( connecting.wifiPassword = self.wifiPwd;
CNCopyCurrentNetworkInfo((__bridge CFStringRef)interfaceName)); connecting.deviceType=self.deviceType;
BOOL isNotEmpty = (SSIDInfo.count > 0); [self.navigationController pushViewController:connecting animated:YES];
if (isNotEmpty) { }
break;
}else{
[self.view makeToast:@"WiFi名称不匹配请重试"];
} }
} }];
return SSIDInfo;
} }
// //
-(void)viewWillEnterForeground:(NSNotification *)noti{ -(void)viewWillEnterForeground:(NSNotification *)noti{
if (self.isGoChangeWiFi) { 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];
});
} }
} }
/* /*

View File

@ -143,14 +143,17 @@ Strong UILabel *subTitleLabel;
// //
}else{ }else{
ConAquarNowWiFiPwdVC *vc = InitObject(ConAquarNowWiFiPwdVC); [CommonUtils getNetworkTypeComplete:^(NSString *netconnType, NSString *BSSID, NSString *SSID) {
vc.deviceType=self.deviceType; ConAquarNowWiFiPwdVC *vc = InitObject(ConAquarNowWiFiPwdVC);
NSDictionary *netInfo = [CommonUtils getSSIDInfo]; vc.deviceType=self.deviceType;
vc.ssid = [netInfo objectForKey:@"SSID"];
vc.bssid = [netInfo objectForKey:@"BSSID"]; vc.ssid = SSID;
vc.deviceType=self.deviceType; vc.bssid = BSSID;
vc.deviceType=self.deviceType;
[self.navigationController pushViewController:vc animated:YES];
}];
[self.navigationController pushViewController:vc animated:YES];
} }
} }
- (UILabel *)subTitleLabel - (UILabel *)subTitleLabel

View File

@ -200,31 +200,21 @@ Strong UIButton *nextBtn;
} }
-(void)connectMyWIFI{ -(void)connectMyWIFI{
NSUserDefaults*userDefsult=[NSUserDefaults standardUserDefaults]; [CommonUtils getNetworkTypeComplete:^(NSString *netconnType, NSString *BSSID, NSString *SSID) {
NSString*pass=[userDefsult objectForKey:@"wifiPass"]; NSUserDefaults*userDefsult=[NSUserDefaults standardUserDefaults];
NSDictionary *netInfo = [self getSSIDInfo]; NSString*pass=[userDefsult objectForKey:@"wifiPass"];
_ssid = [netInfo objectForKey:@"SSID"];
_bssid = [netInfo objectForKey:@"BSSID"];
self.wifiPwdTextField.text=pass; _ssid = SSID;
self.wifiNameTextField.text = [netInfo objectForKey:@"SSID"]; _bssid = BSSID;
self.wifiPwdTextField.text=pass;
self.wifiNameTextField.text = SSID;
}];
} }
// refer to http://stackoverflow.com/questions/5198716/iphone-get-ssid-without-private-library // 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 #pragma mark --buttonClick
-(void)nextBtnClick:(UIButton *)sender{ -(void)nextBtnClick:(UIButton *)sender{
BOOL isRight =[dataContorl isIncludeSpecialCharact:self.wifiPwdTextField.text]; BOOL isRight =[dataContorl isIncludeSpecialCharact:self.wifiPwdTextField.text];

View File

@ -244,18 +244,7 @@ Copy NSString *deviceId;
} }
#pragma mark - UDP related #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 { - (void)sendToDeviceWithSSIDName:(NSString *)name andSSIDPWD:(NSString *)pwd {
[IFishHotpotUDPHelper sharedInstance].delegate = self; [IFishHotpotUDPHelper sharedInstance].delegate = self;
@ -282,34 +271,34 @@ Copy NSString *deviceId;
- (void)startBinding { - (void)startBinding {
BOOL networkOk = NO; [CommonUtils getNetworkTypeComplete:^(NSString *netconnType, NSString *BSSID, NSString *SSID) {
AFNetworkReachabilityStatus status = [AFNetworkReachabilityManager sharedManager].networkReachabilityStatus; if ([netconnType isEqualToString:@"no network"]||([netconnType isEqualToString:@"Wifi"]&&[SSID.lowercaseString hasPrefix:@"ifish"]))
if (status == AFNetworkReachabilityStatusReachableViaWiFi||status == AFNetworkReachabilityStatusUnknown) { {
if (![[self currentWifiSSID].lowercaseString hasPrefix:@"ifish"]) {
networkOk = YES; //
} }
} else if (status == AFNetworkReachabilityStatusReachableViaWWAN) { else
networkOk = YES; {
} if (self.isBindingDevice) {
if (!networkOk) { return;
return; }
} if (self.macAddress.length == 0) {
if (self.isBindingDevice) { return;
return; }
}
if (self.macAddress.length == 0) { self.retryTimes = 0;
return; if (self.deviceType==DEVICEPETS)
} {
[self showStoreNameView];
}
else
{
[self bindDeviceWithSsid:self.macAddress];
}
}
}];
self.retryTimes = 0;
if (self.deviceType==DEVICEPETS)
{
[self showStoreNameView];
}
else
{
[self bindDeviceWithSsid:self.macAddress];
}
} }

View File

@ -30,15 +30,18 @@
} }
- (IBAction)reset:(id)sender { - (IBAction)reset:(id)sender {
if (![[self currentWifiSSID].lowercaseString hasPrefix:@"ifish"]) { [CommonUtils getNetworkTypeComplete:^(NSString *netconnType, NSString *BSSID, NSString *SSID) {
[self.view makeToast:@"请先将手机连接到wifi:ifish-xxxx"]; if (![SSID.lowercaseString hasPrefix:@"ifish"]) {
return; [self.view makeToast:@"请先将手机连接到wifi:ifish-xxxx"];
} return;
self.HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; }
self.HUD.mode = MBProgressHUDModeIndeterminate; self.HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
self.HUD.labelText = @"重置指令已发出"; self.HUD.mode = MBProgressHUDModeIndeterminate;
[IFishHotpotUDPHelper sharedInstance].delegate = self; self.HUD.labelText = @"重置指令已发出";
[[IFishHotpotUDPHelper sharedInstance] broadCastRestCommand]; [IFishHotpotUDPHelper sharedInstance].delegate = self;
[[IFishHotpotUDPHelper sharedInstance] broadCastRestCommand];
}];
} }
- (IBAction)tipBtnClicked:(id)sender { - (IBAction)tipBtnClicked:(id)sender {
@ -62,17 +65,6 @@
#pragma mark - #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 @end

View File

@ -25,7 +25,7 @@
// CFShow((__bridge CFTypeRef)(infoDic)); // CFShow((__bridge CFTypeRef)(infoDic));
NSString *app_Version=[infoDic objectForKey:@"CFBundleShortVersionString"]; NSString *app_Version=[infoDic objectForKey:@"CFBundleShortVersionString"];
NSLog(@"app_Version%@",app_Version); NSLog(@"app_Version%@",app_Version);
app_Version=@"4.7.21"; app_Version=@"4.7.22";
NSString *versionStr = [NSString stringWithFormat:@"v%@",app_Version]; NSString *versionStr = [NSString stringWithFormat:@"v%@",app_Version];
NSString *buildVersion = [infoDic objectForKey:@"CFBundleVersion"]; NSString *buildVersion = [infoDic objectForKey:@"CFBundleVersion"];
if (buildVersion.length > 0) { if (buildVersion.length > 0) {

View File

@ -125,21 +125,7 @@ typedef NS_ENUM(NSInteger,lodingViewdissMissStyle) {
} }
//获取WiFi信息 //获取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{ -(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated]; [super viewWillDisappear:animated];
@ -164,123 +150,125 @@ typedef NS_ENUM(NSInteger,lodingViewdissMissStyle) {
} }
-(void)initComponent{ -(void)initComponent{
//967/1018/ 0.95 //967/1018/ 0.95
[CommonUtils getNetworkTypeComplete:^(NSString *netconnType, NSString *BSSID, NSString *SSID) {
CGFloat percentHbiW = 0.117 ;//5s 35/300 CGFloat percentHbiW = 0.117 ;//5s 35/300
CGFloat y = 20; CGFloat y = 20;
self.nodImg= [[UIImageView alloc] initWithFrame:CGRectMake(5, y,12, 12)]; self.nodImg= [[UIImageView alloc] initWithFrame:CGRectMake(5, y,12, 12)];
self.nodImg.image = [UIImage imageNamed:@"linkingdevice_point"]; self.nodImg.image = [UIImage imageNamed:@"linkingdevice_point"];
[self.view addSubview:self.nodImg]; [self.view addSubview:self.nodImg];
self.wifilabel=[[UILabel alloc] init]; self.wifilabel=[[UILabel alloc] init];
NSDictionary *ifs = [self fetchSSIDInfo];
if (!self.wifiName.length) if (!self.wifiName.length)
{ {
self.wifiName = [ifs objectForKey:@"SSID"]; self.wifiName = SSID;
} }
self.wifilabel.text = [NSString stringWithFormat:@"请输入当前WiFi:%@密码",self.wifiName]; self.wifilabel.text = [NSString stringWithFormat:@"请输入当前WiFi:%@密码",self.wifiName];
self.wifilabel.textAlignment = NSTextAlignmentLeft; 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]; 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]; NSMutableAttributedString * attributedString = [[NSMutableAttributedString alloc] initWithString:self.wifilabel.text];
NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init]; NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setLineSpacing:8]; [paragraphStyle setLineSpacing:8];
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [self.wifilabel.text length])]; [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)]; [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 setAttributedText:attributedString];
[self.wifilabel sizeToFit]; [self.wifilabel sizeToFit];
CGFloat labelSizeW = [self widthForString:self.wifilabel.text fontSize:18 andHeight:10]; CGFloat labelSizeW = [self widthForString:self.wifilabel.text fontSize:18 andHeight:10];
CGFloat labelH= [self heightForString:self.wifilabel.text fontSize:18 andWidth:labelSizeW]; CGFloat labelH= [self heightForString:self.wifilabel.text fontSize:18 andWidth:labelSizeW];
self.wifilabel.frame = CGRectMake(CGRectGetMaxX(self.nodImg.frame), y, labelSizeW, labelH); self.wifilabel.frame = CGRectMake(CGRectGetMaxX(self.nodImg.frame), y, labelSizeW, labelH);
[self.view addSubview:self.wifilabel]; [self.view addSubview:self.wifilabel];
//wifi 输入框 //wifi 输入框
CGFloat wifiFileW=kScreenSize.width - 2*10; CGFloat wifiFileW=kScreenSize.width - 2*10;
CGFloat wifiFileH=wifiFileW*percentHbiW; CGFloat wifiFileH=wifiFileW*percentHbiW;
self.wifiSecFiled=[[UITextField alloc] initWithFrame:CGRectMake(10,CGRectGetMaxY(self.wifilabel.frame) + 10, wifiFileW, wifiFileH)]; self.wifiSecFiled=[[UITextField alloc] initWithFrame:CGRectMake(10,CGRectGetMaxY(self.wifilabel.frame) + 10, wifiFileW, wifiFileH)];
self.wifiSecFiled.placeholder = @"请输入WiFi密码"; self.wifiSecFiled.placeholder = @"请输入WiFi密码";
self.wifiSecFiled.delegate=self; self.wifiSecFiled.delegate=self;
self.wifiSecFiled.keyboardType=UIKeyboardTypeAlphabet; self.wifiSecFiled.keyboardType=UIKeyboardTypeAlphabet;
self.wifiSecFiled.layer.masksToBounds=YES; self.wifiSecFiled.layer.masksToBounds=YES;
self.wifiSecFiled.layer.cornerRadius=5; self.wifiSecFiled.layer.cornerRadius=5;
if (@available(iOS 13.0, *)){//iOS13之后设置颜色的方便变更 if (@available(iOS 13.0, *)){//iOS13之后设置颜色的方便变更
}else{ }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 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.borderStyle = UITextBorderStyleNone;
self.wifiSecFiled.backgroundColor = [UIColor colorWithRed:244.0/255.0 green:244.0/255.0 blue:244.0/255.0 alpha:1]; 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]; NSUserDefaults*userDefsult=[NSUserDefaults standardUserDefaults];
NSString*pass=[userDefsult objectForKey:@"wifiPass"]; NSString*pass=[userDefsult objectForKey:@"wifiPass"];
if (pass) { if (pass) {
self.wifiSecFiled.text = pass; self.wifiSecFiled.text = pass;
} }
self.wifiSecFiled.textAlignment = NSTextAlignmentLeft; self.wifiSecFiled.textAlignment = NSTextAlignmentLeft;
[self.view addSubview:self.wifiSecFiled]; [self.view addSubview:self.wifiSecFiled];
//占位view 让输入框文字 偏移 也有别的方法 contentoffset //占位view 让输入框文字 偏移 也有别的方法 contentoffset
UIView*phoneView=[[UIView alloc]initWithFrame:CGRectMake(0,0, 9, 10)]; UIView*phoneView=[[UIView alloc]initWithFrame:CGRectMake(0,0, 9, 10)];
self.wifiSecFiled.leftView=phoneView; self.wifiSecFiled.leftView=phoneView;
self.wifiSecFiled.leftViewMode=UITextFieldViewModeAlways; self.wifiSecFiled.leftViewMode=UITextFieldViewModeAlways;
CGFloat btnW=100; CGFloat btnW=100;
//输入框内白色2像素view //输入框内白色2像素view
UIView *whiteView=[[UIView alloc] initWithFrame:CGRectMake(wifiFileW - btnW -2, 0, 2, wifiFileH)]; UIView *whiteView=[[UIView alloc] initWithFrame:CGRectMake(wifiFileW - btnW -2, 0, 2, wifiFileH)];
whiteView.backgroundColor = [UIColor whiteColor]; whiteView.backgroundColor = [UIColor whiteColor];
[self.wifiSecFiled addSubview:whiteView]; [self.wifiSecFiled addSubview:whiteView];
self.sBtn=[UIButton buttonWithType:UIButtonTypeCustom]; self.sBtn=[UIButton buttonWithType:UIButtonTypeCustom];
[self.sBtn setTitle:@"确定" forState:UIControlStateNormal]; [self.sBtn setTitle:@"确定" forState:UIControlStateNormal];
self.sBtn.frame = CGRectMake(wifiFileW - btnW,0, btnW,wifiFileH); self.sBtn.frame = CGRectMake(wifiFileW - btnW,0, btnW,wifiFileH);
[self.sBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [self.sBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[self.sBtn addTarget:self action:@selector(sBtn:) forControlEvents:UIControlEventTouchUpInside]; [self.sBtn addTarget:self action:@selector(sBtn:) forControlEvents:UIControlEventTouchUpInside];
//self.sBtn.backgroundColor = COLOR_LABEL_TITLE; //self.sBtn.backgroundColor = COLOR_LABEL_TITLE;
[self.sBtn setBackgroundImage:[UIImage imageNamed:@"linkingdevice_botton"] forState:UIControlStateNormal]; [self.sBtn setBackgroundImage:[UIImage imageNamed:@"linkingdevice_botton"] forState:UIControlStateNormal];
[self.wifiSecFiled addSubview:self.sBtn]; [self.wifiSecFiled addSubview:self.sBtn];
//底部背景 //底部背景
UIImageView *backImg=[[UIImageView alloc] initWithFrame:CGRectMake(0,kScreenSize.height - kScreenSize.width * 1.1,kScreenSize.width,kScreenSize.width * 1.1)]; 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.image = [UIImage imageNamed:@"linkingdevice_setting"];
backImg.userInteractionEnabled = YES; backImg.userInteractionEnabled = YES;
[self.view addSubview:backImg]; [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.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=[[UILabel alloc]initWithFrame:CGRectMake(30, CGRectGetMidY(self.waveProgressView.frame), kScreenWidth-60, 130)];
self.attentionLabel.font=[UIFont systemFontOfSize:13]; self.attentionLabel.font=[UIFont systemFontOfSize:13];
self.attentionLabel.textColor=[UIColor blackColor]; self.attentionLabel.textColor=[UIColor blackColor];
self.attentionLabel.numberOfLines=0; self.attentionLabel.numberOfLines=0;
self.attentionLabel.text=@"1、请长按摄像头背后复位孔复位摄像头。\n2、若Wifi名称有中文请改成英文字母加数字。\n3、Wifi密码不能包含特殊符号“等。\n4、若多次智能连接未成功请尝试热点模式连接。"; self.attentionLabel.text=@"1、请长按摄像头背后复位孔复位摄像头。\n2、若Wifi名称有中文请改成英文字母加数字。\n3、Wifi密码不能包含特殊符号“等。\n4、若多次智能连接未成功请尝试热点模式连接。";
[self.view addSubview:self.waveProgressView]; [self.view addSubview:self.waveProgressView];
[self.view bringSubviewToFront:self.waveProgressView]; [self.view bringSubviewToFront:self.waveProgressView];
[self.view addSubview:self.attentionLabel]; [self.view addSubview:self.attentionLabel];
//说明书 //说明书
UIButton *shuimingshuBtn=[UIButton buttonWithType:UIButtonTypeCustom]; UIButton *shuimingshuBtn=[UIButton buttonWithType:UIButtonTypeCustom];
shuimingshuBtn.frame = CGRectMake(0,kScreenSize.height - 44 - 200, kScreenSize.width*1/3, 200); shuimingshuBtn.frame = CGRectMake(0,kScreenSize.height - 44 - 200, kScreenSize.width*1/3, 200);
[shuimingshuBtn addTarget:self action:@selector(ChaKanShuimingShu) forControlEvents:UIControlEventTouchUpInside]; [shuimingshuBtn addTarget:self action:@selector(ChaKanShuimingShu) forControlEvents:UIControlEventTouchUpInside];
//[shuimingshuBtn setBackgroundColor:[UIColor redColor]]; //[shuimingshuBtn setBackgroundColor:[UIColor redColor]];
[self.view addSubview:shuimingshuBtn]; [self.view addSubview:shuimingshuBtn];
//设置输入状态UI //设置输入状态UI
[self connectNormalView]; [self connectNormalView];
}];
} }
@ -315,14 +303,16 @@ self.attentionLabel.text=@"1、请长按摄像头背后复位孔复位摄像
#pragma mark- 点击确定 #pragma mark- 点击确定
-(void)goAPmode -(void)goAPmode
{ {
ConAquarNowWiFiPwdVC *vc = InitObject(ConAquarNowWiFiPwdVC); [CommonUtils getNetworkTypeComplete:^(NSString *netconnType, NSString *BSSID, NSString *SSID) {
vc.deviceType=DEVICECAMERA; ConAquarNowWiFiPwdVC *vc = InitObject(ConAquarNowWiFiPwdVC);
NSDictionary *netInfo = [CommonUtils getSSIDInfo]; vc.deviceType=DEVICECAMERA;
vc.ssid = [netInfo objectForKey:@"SSID"];
vc.bssid = [netInfo objectForKey:@"BSSID"]; vc.ssid = SSID;
vc.bssid = BSSID;
[self.navigationController pushViewController:vc animated:YES]; [self.navigationController pushViewController:vc animated:YES];
}];
} }
-(void)sBtn:(UIButton*)btn{ -(void)sBtn:(UIButton*)btn{
NSString *ssidName =@""; NSString *ssidName =@"";
@ -519,21 +509,23 @@ self.attentionLabel.text=@"1、请长按摄像头背后复位孔复位摄像
{ {
// //
if (self.deviceID.length&&![self.linkDict[self.deviceID] boolValue]) {//90秒之后还未连接上连接超时 if (self.deviceID.length&&![self.linkDict[self.deviceID] boolValue]) {//90秒之后还未连接上连接超时
[[GWP2PDeviceLinker shareInstance] p2pStopSmartLink]; [CommonUtils getNetworkTypeComplete:^(NSString *netconnType, NSString *BSSID, NSString *SSID) {
[[GWP2PDeviceLinker shareInstance] p2pStopAPLink]; [[GWP2PDeviceLinker shareInstance] p2pStopSmartLink];
[[GWP2PDeviceLinker shareInstance] p2pStopAPLink];
if ([[[CommonUtils getSSIDInfo] objectForKey:@"SSID"] isEqualToString:self.wifiName]) if ([SSID isEqualToString:self.wifiName])
{ {
[self.view makeToast:@"请确保Wifi密码正确,重置设备后再试!"]; [self.view makeToast:@"请确保Wifi密码正确,重置设备后再试!"];
} }
else else
{ {
[self.view makeToast:[NSString stringWithFormat:@"WiFi连接失败请确保手机连接到%@",self.wifiName]]; [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(), ^{ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.navigationController popViewControllerAnimated:YES]; [self.navigationController popViewControllerAnimated:YES];
}); });
}];
} }
else if(!self.deviceID.length) else if(!self.deviceID.length)

View File

@ -13,7 +13,7 @@
#import "AppDelegate.h" #import "AppDelegate.h"
#import "Utils.h" #import "Utils.h"
#import "UDManager.h" #import "UDManager.h"
#import "Reachability.h"
#include <sys/types.h> #include <sys/types.h>
#include <stdint.h> #include <stdint.h>
#include <unistd.h> #include <unistd.h>
@ -161,8 +161,7 @@ withFilterContext:(id)filterContext
while (1) while (1)
{ {
//wifiap //wifiap
NSString* ssid = [Utils currentWifiSSID]; if ([Reachability reachabilityForInternetConnection].currentReachabilityStatus!=ReachableViaWiFi) {
if (ssid == nil) {
NSLog(@"get ap mode info failed, no wifi"); NSLog(@"get ap mode info failed, no wifi");
break; break;
} }

View File

@ -117,7 +117,7 @@
while (1) while (1)
{ {
//wifi //wifi
NSString* ssid = [Utils currentWifiSSID]; BOOL iswifi = ([Reachability reachabilityForInternetConnection].currentReachabilityStatus==ReachableViaWiFi);
//ap //ap
int dwApContactID = [[AppDelegate sharedDefault] dwApContactID]; int dwApContactID = [[AppDelegate sharedDefault] dwApContactID];
@ -125,7 +125,7 @@
// //
UIApplicationState iState = [UIApplication sharedApplication].applicationState; UIApplicationState iState = [UIApplication sharedApplication].applicationState;
_isConditionOK = (ssid != nil && _isConditionOK = (iswifi &&
dwApContactID == 0 && dwApContactID == 0 &&
iState != UIApplicationStateBackground); iState != UIApplicationStateBackground);

View File

@ -76,25 +76,14 @@ Copy NSString *wifiName;//当前wifi名称
// //
// self.navigationItem.leftBarButtonItem=backItem; // self.navigationItem.leftBarButtonItem=backItem;
NSDictionary *wifiDic = [self fetchSSIDInfo]; [CommonUtils getNetworkTypeComplete:^(NSString *netconnType, NSString *BSSID, NSString *SSID) {
NSString *wifiName = [wifiDic objectForKey:@"SSID"]; self.wifiNameTextField.text = SSID;
self.wifiNameTextField.text = wifiName; }];
} }
//WiFi //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{ -(void)clickBack{
[self.navigationController popViewControllerAnimated:YES]; [self.navigationController popViewControllerAnimated:YES];
} }
@ -154,40 +143,31 @@ Copy NSString *wifiName;//当前wifi名称
return YES; return YES;
} }
- (IBAction)setLinkBtnClicked:(id)sender { - (IBAction)setLinkBtnClicked:(id)sender {
if (self.nameLbl.text.length == 0) { [CommonUtils getNetworkTypeComplete:^(NSString *netconnType, NSString *BSSID, NSString *SSID) {
[self.view makeToast:@"请输入正确的路由器名称"]; if (self.nameLbl.text.length == 0) {
return; [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];
}
- (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"];
} }
} BOOL isRight =[dataContorl isIncludeSpecialCharact:self.pwdTf.text];
return ssid;
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];
}];
} }
#pragma mark - UDP related #pragma mark - UDP related
- (void)sendToDeviceWithSSIDName:(NSString *)name andSSIDPWD:(NSString *)pwd { - (void)sendToDeviceWithSSIDName:(NSString *)name andSSIDPWD:(NSString *)pwd {
@ -213,31 +193,34 @@ Copy NSString *wifiName;//当前wifi名称
} }
- (void)startBinding { - (void)startBinding {
BOOL networkOk = NO;
AFNetworkReachabilityStatus status = [AFNetworkReachabilityManager sharedManager].networkReachabilityStatus; [CommonUtils getNetworkTypeComplete:^(NSString *netconnType, NSString *BSSID, NSString *SSID) {
if (status == AFNetworkReachabilityStatusReachableViaWiFi) { if ([netconnType isEqualToString:@"no network"]||([netconnType isEqualToString:@"Wifi"]&&[SSID.lowercaseString hasPrefix:@"ifish"]))
if (![[self currentWifiSSID].lowercaseString hasPrefix:@"ifish"]) { {
networkOk = YES;
//
} }
} else if (status == AFNetworkReachabilityStatusReachableViaWWAN) { else
networkOk = YES; {
} if (self.isBindingDevice) {
if (!networkOk) { return;
return; }
} if (self.macAddress.length == 0) {
if (self.isBindingDevice) { return;
return; }
}
if (self.macAddress.length == 0) { self.isBindingDevice = YES;
return; if (self.bindTimer) {
} [self.bindTimer invalidate];
self.isBindingDevice = YES; self.bindTimer = nil;
if (self.bindTimer) { }
[self.bindTimer invalidate]; self.retryTimes = 0;
self.bindTimer = nil; [self bindDeviceWithSsid:self.macAddress];
}
self.retryTimes = 0; }
[self bindDeviceWithSsid:self.macAddress]; }];
} }
- (void)udpHelperMessage:(NSString *)msg { - (void)udpHelperMessage:(NSString *)msg {

View File

@ -245,31 +245,33 @@ extern BOOL formLogIn;//连接页面是否来自登录界面
}]; }];
} }
-(void)connectMyWIFI{ -(void)connectMyWIFI{
[CommonUtils getNetworkTypeComplete:^(NSString *netconnType, NSString *BSSID, NSString *SSID) {
NSUserDefaults*userDefsult=[NSUserDefaults standardUserDefaults];
NSString*pass=[userDefsult objectForKey:@"wifiPass"];
NSUserDefaults*userDefsult=[NSUserDefaults standardUserDefaults]; _ssid = SSID;
NSString*pass=[userDefsult objectForKey:@"wifiPass"]; _bssid = BSSID;
NSDictionary *netInfo = [self fetchNetInfo]; NSString *msg = [NSString stringWithFormat:@"请输入%@密码",_ssid];
_ssid = [netInfo objectForKey:@"SSID"]; UIAlertView *alerV = [[UIAlertView alloc]initWithTitle:msg
_bssid = [netInfo objectForKey:@"BSSID"]; message:nil
NSString *msg = [NSString stringWithFormat:@"请输入%@密码",_ssid]; delegate:self
UIAlertView *alerV = [[UIAlertView alloc]initWithTitle:msg cancelButtonTitle:@"取消"
message:nil otherButtonTitles:@"确定", nil];
delegate:self alerV.alertViewStyle = UIAlertViewStylePlainTextInput;
cancelButtonTitle:@"取消" _wifiFiled=[alerV textFieldAtIndex:0];
otherButtonTitles:@"确定", nil]; _wifiFiled.secureTextEntry=NO;
alerV.alertViewStyle = UIAlertViewStylePlainTextInput; _wifiFiled.text=pass;
_wifiFiled=[alerV textFieldAtIndex:0]; _wifiFiled.clearButtonMode=UITextFieldViewModeAlways;
_wifiFiled.secureTextEntry=NO; alerV.tag=ALERTVIEW_TAG;
_wifiFiled.text=pass;
_wifiFiled.clearButtonMode=UITextFieldViewModeAlways;
alerV.tag=ALERTVIEW_TAG;
[alerV show]; [alerV show];
// [self bindDeviceWithSsid:@"5CCF7F0065CA"]; // [self bindDeviceWithSsid:@"5CCF7F0065CA"];
// 5CCF7F00669C // 5CCF7F00669C
// 5CCF7F006668 // 5CCF7F006668
// 5CCF7F0065CA // 5CCF7F0065CA
}];
} }
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
@ -395,39 +397,12 @@ extern BOOL formLogIn;//连接页面是否来自登录界面
[userdefult synchronize]; [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 // 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 #pragma mark
-(void)bindDeviceWithSsid:(NSString*)bssid{ -(void)bindDeviceWithSsid:(NSString*)bssid{

View File

@ -492,33 +492,35 @@ extern BOOL isfromCameraView;
} }
-(void)connectMyWIFI{ -(void)connectMyWIFI{
[CommonUtils getNetworkTypeComplete:^(NSString *netconnType, NSString *BSSID, NSString *SSID) {
NSUserDefaults*userDefsult=[NSUserDefaults standardUserDefaults]; NSUserDefaults*userDefsult=[NSUserDefaults standardUserDefaults];
NSString*pass=[userDefsult objectForKey:@"wifiPass"]; NSString*pass=[userDefsult objectForKey:@"wifiPass"];
NSDictionary *netInfo = [self fetchNetInfo];
_ssid = [netInfo objectForKey:@"SSID"];
_bssid = [netInfo objectForKey:@"BSSID"];
NSString *msg = [NSString stringWithFormat:@"请输入当前WiFi:%@的密码",_ssid]; _ssid = SSID;
_bssid = BSSID;
NSMutableAttributedString * attributedString = [[NSMutableAttributedString alloc] initWithString:msg]; NSString *msg = [NSString stringWithFormat:@"请输入当前WiFi:%@的密码",_ssid];
NSMutableParagraphStyle *paraghStyle =[[NSMutableParagraphStyle alloc] init]; NSMutableAttributedString * attributedString = [[NSMutableAttributedString alloc] initWithString:msg];
[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]; NSMutableParagraphStyle *paraghStyle =[[NSMutableParagraphStyle alloc] init];
_wifiTextFiled.secureTextEntry=NO; [paraghStyle setLineSpacing:4];
_wifiTextFiled.text=pass; [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)];
_wifiTextFiled.clearButtonMode=UITextFieldViewModeAlways; [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"]; //[self bindDeviceWithSsid:@"5ccf7f003a93"];
// 5CCF7F00669C // 5CCF7F00669C
// 5CCF7F006668 // 5CCF7F006668
// 5CCF7F0065CA // 5CCF7F0065CA
}];
} }
-(void)checkLocation{ -(void)checkLocation{
NSString* phoneVersion = [[UIDevice currentDevice] systemVersion]; 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 // 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 //wifi
-(void)savePassw{ -(void)savePassw{