获取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)
{ {
[CommonUtils getNetworkTypeComplete:^(NSString *netconnType, NSString *BSSID, NSString *SSID) {
self.dwApContactID = ap3cid; self.dwApContactID = ap3cid;
self.sWifi = [Utils currentWifiSSID]; self.sWifi = SSID;
[[UDPManager sharedDefault] ScanLanDevice]; [[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,14 +117,15 @@ 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"];
NSString *wifiName = SSID;
//wifiwifiwifi //wifiwifiwifi
if ([wifiName isEqualToString:self.wifiName]) { if ([wifiName isEqualToString:self.wifiName]) {
[self.view makeToast:@"请先连接设备热点"]; [self.view makeToast:@"请先连接设备热点"];
return; return;
} }
if ([wifiName rangeOfString:@"ifish"].location!=NSNotFound||[wifiName rangeOfString:@"GW"].location!=NSNotFound||[wifiName.lowercaseString isEqualToString:@"wlan"]||![wifiName isEqualToString:self.wifiName]) { if ([wifiName rangeOfString:@"ifish"].location!=NSNotFound||[wifiName rangeOfString:@"GW"].location!=NSNotFound) {
//wifi //wifi
if(self.deviceType==DEVICECAMERA) if(self.deviceType==DEVICECAMERA)
{ {
@ -149,25 +150,17 @@ Assign BOOL isGoChangeWiFi;//更换为设备的WiFi
}else{ }else{
[self.view makeToast:@"WiFi名称不匹配请重试"]; [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{ -(void)viewWillEnterForeground:(NSNotification *)noti{
if (self.isGoChangeWiFi) { if (self.isGoChangeWiFi) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.35 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self checkWiFi]; [self checkWiFi];
});
} }
} }
/* /*

View File

@ -143,14 +143,17 @@ Strong UILabel *subTitleLabel;
// //
}else{ }else{
[CommonUtils getNetworkTypeComplete:^(NSString *netconnType, NSString *BSSID, NSString *SSID) {
ConAquarNowWiFiPwdVC *vc = InitObject(ConAquarNowWiFiPwdVC); ConAquarNowWiFiPwdVC *vc = InitObject(ConAquarNowWiFiPwdVC);
vc.deviceType=self.deviceType; vc.deviceType=self.deviceType;
NSDictionary *netInfo = [CommonUtils getSSIDInfo];
vc.ssid = [netInfo objectForKey:@"SSID"]; vc.ssid = SSID;
vc.bssid = [netInfo objectForKey:@"BSSID"]; vc.bssid = BSSID;
vc.deviceType=self.deviceType; 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{
[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 getSSIDInfo];
_ssid = [netInfo objectForKey:@"SSID"]; _ssid = SSID;
_bssid = [netInfo objectForKey:@"BSSID"]; _bssid = BSSID;
self.wifiPwdTextField.text=pass; self.wifiPwdTextField.text=pass;
self.wifiNameTextField.text = [netInfo objectForKey:@"SSID"]; 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,18 +271,14 @@ 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) {
networkOk = YES;
}
if (!networkOk) {
return;
} }
else
{
if (self.isBindingDevice) { if (self.isBindingDevice) {
return; return;
} }
@ -310,6 +295,10 @@ Copy NSString *deviceId;
{ {
[self bindDeviceWithSsid:self.macAddress]; [self bindDeviceWithSsid:self.macAddress];
} }
}
}];
} }

View File

@ -30,7 +30,8 @@
} }
- (IBAction)reset:(id)sender { - (IBAction)reset:(id)sender {
if (![[self currentWifiSSID].lowercaseString hasPrefix:@"ifish"]) { [CommonUtils getNetworkTypeComplete:^(NSString *netconnType, NSString *BSSID, NSString *SSID) {
if (![SSID.lowercaseString hasPrefix:@"ifish"]) {
[self.view makeToast:@"请先将手机连接到wifi:ifish-xxxx"]; [self.view makeToast:@"请先将手机连接到wifi:ifish-xxxx"];
return; return;
} }
@ -39,6 +40,8 @@
self.HUD.labelText = @"重置指令已发出"; self.HUD.labelText = @"重置指令已发出";
[IFishHotpotUDPHelper sharedInstance].delegate = self; [IFishHotpotUDPHelper sharedInstance].delegate = self;
[[IFishHotpotUDPHelper sharedInstance] broadCastRestCommand]; [[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,7 +150,7 @@ 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)];
@ -173,10 +159,10 @@ typedef NS_ENUM(NSInteger,lodingViewdissMissStyle) {
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;
} }
@ -265,7 +251,7 @@ typedef NS_ENUM(NSInteger,lodingViewdissMissStyle) {
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];
@ -282,6 +268,8 @@ self.attentionLabel.text=@"1、请长按摄像头背后复位孔复位摄像
//设置输入状态UI //设置输入状态UI
[self connectNormalView]; [self connectNormalView];
}];
} }
@ -315,14 +303,16 @@ self.attentionLabel.text=@"1、请长按摄像头背后复位孔复位摄像
#pragma mark- 点击确定 #pragma mark- 点击确定
-(void)goAPmode -(void)goAPmode
{ {
[CommonUtils getNetworkTypeComplete:^(NSString *netconnType, NSString *BSSID, NSString *SSID) {
ConAquarNowWiFiPwdVC *vc = InitObject(ConAquarNowWiFiPwdVC); ConAquarNowWiFiPwdVC *vc = InitObject(ConAquarNowWiFiPwdVC);
vc.deviceType=DEVICECAMERA; vc.deviceType=DEVICECAMERA;
NSDictionary *netInfo = [CommonUtils getSSIDInfo];
vc.ssid = [netInfo objectForKey:@"SSID"]; vc.ssid = SSID;
vc.bssid = [netInfo objectForKey:@"BSSID"]; 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,10 +509,11 @@ self.attentionLabel.text=@"1、请长按摄像头背后复位孔复位摄像
{ {
// //
if (self.deviceID.length&&![self.linkDict[self.deviceID] boolValue]) {//90秒之后还未连接上连接超时 if (self.deviceID.length&&![self.linkDict[self.deviceID] boolValue]) {//90秒之后还未连接上连接超时
[CommonUtils getNetworkTypeComplete:^(NSString *netconnType, NSString *BSSID, NSString *SSID) {
[[GWP2PDeviceLinker shareInstance] p2pStopSmartLink]; [[GWP2PDeviceLinker shareInstance] p2pStopSmartLink];
[[GWP2PDeviceLinker shareInstance] p2pStopAPLink]; [[GWP2PDeviceLinker shareInstance] p2pStopAPLink];
if ([[[CommonUtils getSSIDInfo] objectForKey:@"SSID"] isEqualToString:self.wifiName]) if ([SSID isEqualToString:self.wifiName])
{ {
[self.view makeToast:@"请确保Wifi密码正确,重置设备后再试!"]; [self.view makeToast:@"请确保Wifi密码正确,重置设备后再试!"];
} }
@ -534,6 +525,7 @@ self.attentionLabel.text=@"1、请长按摄像头背后复位孔复位摄像
[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,6 +143,7 @@ Copy NSString *wifiName;//当前wifi名称
return YES; return YES;
} }
- (IBAction)setLinkBtnClicked:(id)sender { - (IBAction)setLinkBtnClicked:(id)sender {
[CommonUtils getNetworkTypeComplete:^(NSString *netconnType, NSString *BSSID, NSString *SSID) {
if (self.nameLbl.text.length == 0) { if (self.nameLbl.text.length == 0) {
[self.view makeToast:@"请输入正确的路由器名称"]; [self.view makeToast:@"请输入正确的路由器名称"];
return; return;
@ -165,7 +155,7 @@ Copy NSString *wifiName;//当前wifi名称
return; return;
} }
if (![[self currentWifiSSID].lowercaseString hasPrefix:@"ifish"]) { if (![SSID.lowercaseString hasPrefix:@"ifish"]) {
[self.view makeToast:@"请先将手机连接到wifi:ifish-xxxx"]; [self.view makeToast:@"请先将手机连接到wifi:ifish-xxxx"];
return; return;
} }
@ -173,20 +163,10 @@ Copy NSString *wifiName;//当前wifi名称
NSString *ssidName = self.nameLbl.text; NSString *ssidName = self.nameLbl.text;
NSString *ssidPwd = self.pwdTf.text; NSString *ssidPwd = self.pwdTf.text;
[self sendToDeviceWithSSIDName:ssidName andSSIDPWD:ssidPwd]; [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 #pragma mark - UDP related
@ -213,24 +193,22 @@ 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) {
networkOk = YES;
}
if (!networkOk) {
return;
} }
else
{
if (self.isBindingDevice) { if (self.isBindingDevice) {
return; return;
} }
if (self.macAddress.length == 0) { if (self.macAddress.length == 0) {
return; return;
} }
self.isBindingDevice = YES; self.isBindingDevice = YES;
if (self.bindTimer) { if (self.bindTimer) {
[self.bindTimer invalidate]; [self.bindTimer invalidate];
@ -238,6 +216,11 @@ Copy NSString *wifiName;//当前wifi名称
} }
self.retryTimes = 0; self.retryTimes = 0;
[self bindDeviceWithSsid:self.macAddress]; [self bindDeviceWithSsid:self.macAddress];
}
}];
} }
- (void)udpHelperMessage:(NSString *)msg { - (void)udpHelperMessage:(NSString *)msg {

View File

@ -245,12 +245,12 @@ extern BOOL formLogIn;//连接页面是否来自登录界面
}]; }];
} }
-(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"]; _ssid = SSID;
_bssid = [netInfo objectForKey:@"BSSID"]; _bssid = BSSID;
NSString *msg = [NSString stringWithFormat:@"请输入%@密码",_ssid]; NSString *msg = [NSString stringWithFormat:@"请输入%@密码",_ssid];
UIAlertView *alerV = [[UIAlertView alloc]initWithTitle:msg UIAlertView *alerV = [[UIAlertView alloc]initWithTitle:msg
message:nil message:nil
@ -271,6 +271,8 @@ extern BOOL formLogIn;//连接页面是否来自登录界面
// 5CCF7F006668 // 5CCF7F006668
// 5CCF7F0065CA // 5CCF7F0065CA
}];
} }
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex==1) { if (buttonIndex==1) {
@ -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,12 +492,13 @@ 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"]; _ssid = SSID;
_bssid = [netInfo objectForKey:@"BSSID"]; _bssid = BSSID;
NSString *msg = [NSString stringWithFormat:@"请输入当前WiFi:%@的密码",_ssid]; NSString *msg = [NSString stringWithFormat:@"请输入当前WiFi:%@的密码",_ssid];
@ -519,6 +520,7 @@ extern BOOL isfromCameraView;
// 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{