摄像头部分的修改

This commit is contained in:
祝发冬 2023-08-21 00:13:29 +08:00
parent 1354f012e1
commit 13ab8a3a3b
2 changed files with 527 additions and 74 deletions

View File

@ -206,7 +206,7 @@ typedef NS_ENUM(NSUInteger, ConnectType) {
ConnectTypeAirKiss = 1,
/// 智能配网
ConnectTypeSmartESPTouch ,
ConnectTypeSmartConfig ,
/// 热点配网
ConnectTypeAP

View File

@ -43,13 +43,36 @@
#import "IfishDataUnity.h"
#import "MyMD5.h"
#import <GWP2P/GWP2P.h>
#import "UIView+Toast.h"
#import "ContactDAO.h"
#import "AppDelegate.h"
#import "UDManager.h"
#import "LoginResult.h"
#import "Utils.h"
#import "RightViewController.h"
#import "LeftViewController.h"
#import "IfishCameraModel.h"
#import "FListManager.h"
#define GIWEI_INITPASS @"123"
#import "IfishP2PMonitorController.h"
#import "LXWaveProgressView.h"
#import "IfishConnectingView.h"
#import "PushMasssageWebViewController.h"
#import "IfishUserObsever.h"
#import <GWP2P/GWP2P.h>
#import "MyMD5.h"
#import "IfishUserDataUnity.h"
#import "DeviceCameraModel.h"
#import "ConAquarChooseWiFiVC.h"
#import "InfoByImageViewController.h"
typedef NS_ENUM(NSInteger,lodingViewdissMissStyle) {
lodingViewdissMissSuccsess=0,// default is 0
lodingViewdissMissfail,
lodingViewdissMissAlreadyBinded
};
@interface ConfigWifiViewController ()<IFishHotpotUDPHelperDelegate,UITextFieldDelegate>
@interface ConfigWifiViewController ()<IFishHotpotUDPHelperDelegate,UITextFieldDelegate,GWPP2PDeviceLinkerProtocol>
@property (nonatomic, strong) NSCondition *_condition;
@property (atomic, strong) ESPTouchTask *_esptouchTask;
@property (nonatomic, strong) EspTouchDelegateImpl *_esptouchDelegate;
@ -65,8 +88,13 @@ typedef NS_ENUM(NSInteger,lodingViewdissMissStyle) {
@property(nonatomic,strong) UILabel *maclabel;
@property (nonatomic, assign) BOOL isGoChangeWiFi;
@property (nonatomic, strong) JMAirKissConnection *airKissConnection; ;
@property (nonatomic, strong) JMAirKissConnection *airKissConnection;
//
@property (strong, nonatomic) NSString *lastSetPassword;
@property (strong,nonatomic) NSMutableDictionary *addresses;
@property (strong,nonatomic) NSMutableDictionary *linkDict;
@property (copy, nonatomic) NSString *deviceID;//id
@property (assign, nonatomic) BOOL isDeviceLinkIn;//
Strong CLLocationManager *locationManager;//iOS13,WiFi
Strong NSMutableString *trackString;
@ -103,7 +131,22 @@ extern BOOL isfromCameraView;
// Do any additional setup after loading the view from its nib.
[self addTitleViewWithTitle:self.titleString];
self.view.backgroundColor=[UIColor whiteColor];
self.connectType = ConnectTypeAirKiss;
if(self.deviceType == DEVICECAMERA)
{
self.connectType = ConnectTypeSmartConfig;
self.connectTypeTitle.text=@"智能配网";
}
else
{
self.connectType = ConnectTypeAirKiss;
}
//
self.isDeviceLinkIn = NO;
[GWP2PDeviceLinker shareInstance].delegate=self;
self.deviceID=nil;
self.addresses = [[NSMutableDictionary alloc] initWithCapacity:1];
self.linkDict = [[NSMutableDictionary alloc] initWithCapacity:1];
_deviceArry =[[NSMutableArray alloc]init];
@ -194,7 +237,7 @@ extern BOOL isfromCameraView;
SPAlertAction*smart =[SPAlertAction actionWithTitle:smartTitle style:SPAlertActionStyleDefault handler:^(SPAlertAction * _Nonnull action) {
[weakSelf connectNormalView];
weakSelf.connectType = ConnectTypeSmartESPTouch;
weakSelf.connectType = ConnectTypeSmartConfig;
weakSelf.connectTypeTitle.text = smartTitle;
weakSelf.connectTipLbl.text = smartTips;
[weakSelf.connectBtn setTitle:@"确定" forState:UIControlStateNormal];
@ -211,7 +254,11 @@ extern BOOL isfromCameraView;
}];
[alert addAction:airkiss];
if(self.deviceType!=DEVICECAMERA)
{
[alert addAction:airkiss];
}
[alert addAction:smart];
[alert addAction:ap];
[alert addAction:cancel];
@ -462,17 +509,11 @@ extern BOOL isfromCameraView;
}
[self savePassw];
if(self.connectType == ConnectTypeAP)
{
[self goSettingClick:nil];
}
else
{
[self configWifiForDevice];
[self configWifiForDevice];
// [self initMMProgressHUD];
[self connectNotNormalView];
}
// [self initMMProgressHUD];
[self connectNotNormalView];
if (_maclabel) {
@ -648,78 +689,89 @@ extern BOOL isfromCameraView;
[self.airKissConnection connectAirKissWithSSID:apSsid
password:apPwd];
}
else if(type==ConnectTypeSmartESPTouch)
else if(type==ConnectTypeSmartConfig)
{
dispatch_async(queue, ^{
NSLog(@"ViewController do the execute work...");
// execute the task
NSArray *esptouchResultArray = [self executeForResults];
// show the result to the user in UI Main Thread
dispatch_async(dispatch_get_main_queue(), ^{
// [self._spinner stopAnimating];
// [self enableConfirmBtn];
ESPTouchResult *firstResult = [esptouchResultArray objectAtIndex:0];
// check whether the task is cancelled and no results received
if (!firstResult.isCancelled)
{
NSMutableString *mutableStr = [[NSMutableString alloc]init];
NSUInteger count = 0;
// max results to be displayed, if it is more than maxDisplayCount,
// just show the count of redundant ones
const int maxDisplayCount = 100000;
if ([firstResult isSuc])
if(self.deviceType == DEVICECAMERA)
{
UIAlertView *alert= [[UIAlertView alloc] initWithTitle:@"提示" message:@"即将使用声波连接,请调大手机音量,并靠近设备,确认设备已经重置(按复位小孔,听到“等待连接“或者“滴”)后再点击确认" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
alert.tag = ALERT_TAG_B_SURE;
[alert show];
}
else
{
dispatch_async(queue, ^{
NSLog(@"ViewController do the execute work...");
// execute the task
NSArray *esptouchResultArray = [self executeForResults];
// show the result to the user in UI Main Thread
dispatch_async(dispatch_get_main_queue(), ^{
// [self._spinner stopAnimating];
// [self enableConfirmBtn];
ESPTouchResult *firstResult = [esptouchResultArray objectAtIndex:0];
// check whether the task is cancelled and no results received
if (!firstResult.isCancelled)
{
success(firstResult.bssid);
for (int i = 0; i < [esptouchResultArray count]; ++i)
NSMutableString *mutableStr = [[NSMutableString alloc]init];
NSUInteger count = 0;
// max results to be displayed, if it is more than maxDisplayCount,
// just show the count of redundant ones
const int maxDisplayCount = 100000;
if ([firstResult isSuc])
{
ESPTouchResult *resultInArray = [esptouchResultArray objectAtIndex:i];
[mutableStr appendString:[resultInArray description]];
[mutableStr appendString:@"\n"];
count++;
if (count >= maxDisplayCount)
success(firstResult.bssid);
for (int i = 0; i < [esptouchResultArray count]; ++i)
{
break;
ESPTouchResult *resultInArray = [esptouchResultArray objectAtIndex:i];
[mutableStr appendString:[resultInArray description]];
[mutableStr appendString:@"\n"];
count++;
if (count >= maxDisplayCount)
{
break;
}
}
if (count < [esptouchResultArray count])
{
[mutableStr appendString:[NSString stringWithFormat:@"\nthere's %lu more result(s) without showing\n",(unsigned long)([esptouchResultArray count] - count)]];
}
}
if (count < [esptouchResultArray count])
else
{
[mutableStr appendString:[NSString stringWithFormat:@"\nthere's %lu more result(s) without showing\n",(unsigned long)([esptouchResultArray count] - count)]];
failure(nil,@"未获取到设备mac");
}
}
else
else if(firstResult.isCancelled)
{
failure(nil,@"未获取到设备mac");
failure(nil,@"连接被取消");
}
}
else if(firstResult.isCancelled)
{
failure(nil,@"连接被取消");
}
else if(!esptouchResultArray.count)
{
failure(nil,@"未有设备响应");
[self.view makeToast:@"未有设备响应"];
else if(!esptouchResultArray.count)
{
failure(nil,@"未有设备响应");
[self.view makeToast:@"未有设备响应"];
}
}
});
});
});
}
}
else if (type == ConnectTypeAP)
{
[self goSettingClick:nil];
}
@ -745,7 +797,16 @@ extern BOOL isfromCameraView;
}
[self.timer invalidate];
self.timer = nil;
[self sendToDeviceWithSSIDName:self.ssid andSSIDPWD:self.wifiPass];
if (self.connectType==ConnectTypeAP&&self.ssid.length&&self.wifiPass.length&&self.deviceType==DEVICECAMERA)
{
[self connectNotNormalView];
[self apLinkConnect];
}
else
{
[self sendToDeviceWithSSIDName:self.ssid andSSIDPWD:self.wifiPass];
}
}];
@ -919,6 +980,401 @@ extern BOOL isfromCameraView;
[self.view addSubview:self.storeNameView];
}
#pragma mark
//
-(void)resetPassWord{
NSString *newPassword = GIWEI_INITPASS;
self.lastSetPassword = [Utils GetTreatedPassword:newPassword];
}
#pragma mark -
/**
UDP使
@param deviceDict
*/
- (void)p2pDeviceLinker:(GWP2PDeviceLinker *)linker deviceLinkSuccess:(NSDictionary *)deviceDict
{
NSLog(@"扫描到设备");
[self deviceLinkin:deviceDict linkType:self.connectType == ConnectTypeAP?conectType_ap:conectType_Intelligent ];
}
-(void)deviceLinkin:(NSDictionary*)deviceDict linkType:(NSInteger)type
{
NSLog(@"声波配网成功,返回数据:%@",deviceDict);
NSString *deviceID = [deviceDict[@"deviceID"] stringValue];
NSString *deviceIP = deviceDict[@"deviceIP"];
if ([self.linkDict[deviceID] boolValue]) {
return;
}
//AP smart
if ([self.deviceID isEqualToString:deviceID]||self.deviceID==nil)
{
if (type==conectType_Intelligent)
{
[self.view makeToast:@"声波配网成功"];
[[GWP2PDeviceLinker shareInstance] p2pStopSmartLink];
}
else
{
[self.view makeToast:@"AP配网成功"];
[[GWP2PDeviceLinker shareInstance] p2pStopAPLink];
}
// NSString *devicePassword = deviceDict[@"devicePassword"];
self.deviceID = deviceID;
self.linkDict[deviceID]=@(YES);
[self resetPassWord];//
if (![deviceDict[@"isInitPassword"] boolValue]){ //,
[[GWP2PClient sharedClient] setDeviceInitialPassword:self.lastSetPassword withDeviceID:deviceIP completionBlock:^(GWP2PClient *client, BOOL success, NSDictionary<NSString *,id> *dataDictionary) {
NSLog(@"success:%i %@",success,dataDictionary);
[self resetPassWord];//
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self bindCameraDevice];
});
}];
}else{//使
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self bindCameraDevice];
});
}
}
}
-(void)deviceLinkinTimeout:(NSInteger)type
{
//
if (self.deviceID.length&&![self.linkDict[self.deviceID] boolValue]) {//90
[CommonUtils getNetworkTypeComplete:^(NSString *netconnType, NSString *BSSID, NSString *SSID) {
[[GWP2PDeviceLinker shareInstance] p2pStopSmartLink];
[[GWP2PDeviceLinker shareInstance] p2pStopAPLink];
if ([SSID isEqualToString:self.ssid])
{
[self.view makeToast:@"请确保Wifi密码正确,重置设备后再试!"];
}
else
{
[self.view makeToast:[NSString stringWithFormat:@"WiFi连接失败请确保手机连接到%@",self.ssid]];
}
[self showFailResultViewWithMsg:@"连接超时"];
}];
}
else if(!self.deviceID.length)
{
[self.view makeToast:@"获取设备ID失败"];
[[GWP2PDeviceLinker shareInstance] p2pStopSmartLink];
[[GWP2PDeviceLinker shareInstance] p2pStopAPLink];
[self connectNormalView];
}
}
-(void)apLinkConnect
{
WEAK_SELF;
[[GWP2PDeviceLinker shareInstance] p2pStopAPLink];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(90 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self deviceLinkinTimeout:self.connectType == ConnectTypeAP?conectType_ap:conectType_Intelligent];
});
[self resetPassWord];//
[[GWP2PDeviceLinker shareInstance] p2pAPLinkDeviceWithWiFiSSID:weakSelf.ssid wifiPassword:weakSelf.wifiPass devicePassword:weakSelf.lastSetPassword deviceReceive:^(NSString *deviceId, BOOL isSupport) {
if (isSupport)
{
weakSelf.deviceID=deviceId;
[weakSelf.view makeToast:[NSString stringWithFormat:@"设备即将连接网络,请将手机自动重新连接到%@",weakSelf.ssid]];
}
else
{
[weakSelf.view makeToast:@"该设备不支持AP配网"];
}
} deviceLinkIn:^(NSDictionary *deviceDict) {
[weakSelf deviceLinkin:deviceDict linkType:weakSelf.connectType == ConnectTypeAP?conectType_ap:conectType_Intelligent];
}];
}
//
-(void)smartLinkConnect{
//AVAudioSession
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
//
//[audioSession overrideOutputAudioPort:AVAudioSessionPortOverrideNone error:nil];
//
[audioSession overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker error:nil];
//App
[audioSession setActive:YES error:nil];
WEAK_SELF;
[[GWP2PDeviceLinker shareInstance] p2pStopSmartLink];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(100 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[[GWP2PDeviceLinker shareInstance] p2pStopSmartLink];
[self deviceLinkinTimeout:self.connectType == ConnectTypeAP?conectType_ap:conectType_Intelligent];
});
[[GWP2PDeviceLinker shareInstance] p2pSmartLinkDeviceWithWiFiSSID:weakSelf.ssid password:weakSelf.wifiPass useSimpleConfig:YES deviceLinkIn:^(NSDictionary *deviceDict) {
[weakSelf deviceLinkin:deviceDict linkType:weakSelf.connectType == ConnectTypeAP?conectType_ap:conectType_Intelligent];
}];
}
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (alertView.tag==ALERT_TAG_B_SURE){
if (buttonIndex ==1) {
//
[self connectNotNormalView];
//
if (self.connectType==ConnectTypeSmartConfig)
{
[self smartLinkConnect];
}
else
{
[self apLinkConnect];
}
}
}//wifi
}
//
-(void)bindCameraDevice{
NSString * contactName = [NSString stringWithFormat:@"Cam%@", self.deviceID];
ContactDAO *contactDAO = [[ContactDAO alloc] init];
Contact *contact = [contactDAO isContact:self.deviceID];
if(contact!=nil){
contact.contactName = contactName;
contact.contactPassword = self.lastSetPassword;//updatepwd
[[FListManager sharedFList] updatee:contact];
[self ifishUserBindcameraIdBy:self.deviceID];
}else{
Contact *contact = [[Contact alloc] init];
contact.contactId = self.deviceID;
contact.contactName = contactName;
contact.contactPassword = self.lastSetPassword;
contact.contactType = CONTACT_TYPE_UNKNOWN;
[[FListManager sharedFList] insert:contact];
//
[self ifishUserBindcameraIdBy:self.deviceID];
}
}
-(void)dealloc{
[[GWP2PDeviceLinker shareInstance] p2pStopSmartLink];
[[GWP2PDeviceLinker shareInstance] p2pStopAPLink];
[[NSNotificationCenter defaultCenter] removeObserver:self name:Noti_WillEnterForeground object:nil];
}
#pragma mark -
//
-(void)ifishUserBindcameraIdBy:(NSString *)cameraId
{
NSLog(@"cameraId = %@",cameraId);
NSMutableArray *oldCameraArr= [[DataCenter defaultDtacenter]valueForKey:@"cameraArr"];
if (!oldCameraArr) {
//
oldCameraArr = [[NSMutableArray alloc] init];
}
IfishCameraModel *camer=[[IfishCameraModel alloc] init];
NSMutableArray *idArr=[[NSMutableArray alloc] init];
for (IfishCameraModel *model in oldCameraArr ) {
[idArr addObject:model.cameraId];
if (model.cameraId == cameraId) {
camer = model;
[self connectNormalView];
[self.view makeToast:@"已经绑定过了"];
return;
}
}
UserModel*model=[[DataCenter defaultDtacenter]valueForKey:@"UserLogIn"];
[AFNOHeaderHttpTool bindCameraWith:cameraId userId:model.userId success:^(id response) {
NSDictionary*resultDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
NSLog(@"%@",resultDic[@"result"]);
if ([resultDic[@"result"] isEqualToString:@"100"]) {
self.lodviewMissStyle =lodingViewdissMissSuccsess;
//
/**
*/
NSMutableArray *newCamerArr = [[NSMutableArray alloc] initWithArray:oldCameraArr];
NSDictionary * cameraDic=resultDic[@"data"];
NSString *newPassword = GIWEI_INITPASS;
NSString *cameraPass = [Utils GetTreatedPassword:newPassword];
IfishCameraModel *camera=[[IfishCameraModel alloc] init];
camera.cameraId = cameraDic[@"cameraId"];
camera.isMaster = cameraDic[@"isMaster"];
camera.showName = cameraDic[@"showName"];
camera.cameraPass = cameraPass;
camera.isActive = cameraDic[@"isActive"];
camera.isLook = cameraDic[@"isLook"];
camera.isLive = cameraDic[@"isLive"];
[newCamerArr insertObject:camera atIndex:0];
//
[[DataCenter defaultDtacenter]setValue: newCamerArr forKey:@"cameraArr"];
NSUserDefaults*userdefult=[NSUserDefaults standardUserDefaults];
NSInteger index=0;
[userdefult setObject:nil forKey:@"lastIndex"];
[userdefult setInteger:index forKey:@"cameralastIndex"];
[userdefult synchronize];
[self setWindowRootWith:camera];
}else{
//lodingViewdissMissSuccsess loding
self.lodviewMissStyle =lodingViewdissMissSuccsess;
[self showFailResultViewWithMsg:@"绑定失败错误码101"];
[self.view makeToast:@"绑定失败错误码101"];
}
} failure:^(NSError *err) {
[self showFailResultViewWithMsg:err.description];
[self.view makeToast:@"绑定失败未知错误"];
}];
}
//
-(void)setWindowRootWith:(IfishCameraModel *)cameraMdel{
[self.view makeToast:@"添加成功"];
[self getMoreUserData:cameraMdel];
}
//
-(void)getMoreUserData:(IfishCameraModel *)cameraMdel{
NSString *userId = [dataContorl dataControlGetUserIdInfo];
[AFHttpTool getMoreUserDataWith:userId success:^(id response) {
NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
NSString *result=reDic[@"result"];
if ([result isEqualToString:@"100"]) {
NSDictionary *dataDic = reDic[@"data"];
//
NSArray*deviceArray=dataDic[@"device"];
NSArray*cameraA=dataDic[@"camera"];
NSMutableArray *deviceArr = [[NSMutableArray alloc] init];
if ([deviceArray count]!=0) {
for (NSDictionary*deviceDic in deviceArray) {
DeviceModel*devicemodel=[[DeviceModel alloc] initWithDict:deviceDic];
[deviceArr insertObject:devicemodel atIndex:0];
}
}
[[DataCenter defaultDtacenter]setValue:deviceArr forKey:@"deviceInfo"];
//
NSMutableArray *camras = [[NSMutableArray alloc] init];
if (cameraA .count !=0) {
if ([cameraA count]!=0) {
for (NSDictionary * cameraDic in cameraA) {
IfishCameraModel *camera=[[IfishCameraModel alloc] initWithDict:cameraDic];
[camras insertObject:camera atIndex:0];
}
}
}
//
[[DataCenter defaultDtacenter]setValue:camras forKey:@"cameraArr"];
/**
*
*/
NSArray*deviceCamera=dataDic[@"deviceCamera"];
NSMutableArray *devicamerArr=[[NSMutableArray alloc] init];
if (deviceCamera) {
for (NSDictionary * deviceCameraDic in deviceCamera) {
DeviceCameraModel *dcmodel=[[DeviceCameraModel alloc] init];
dcmodel.deviceId = deviceCameraDic[@"deviceId"];
dcmodel.cameraId = deviceCameraDic[@"cameraId"];
[devicamerArr addObject:dcmodel];
}
}
//
[[DataCenter defaultDtacenter]setValue:devicamerArr forKey:@"devicamerArr"];
//device
[[GWP2PClient sharedClient] disconnect];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
IfishP2PMonitorController *monitorVC=[[IfishP2PMonitorController alloc] init];
monitorVC.contact = cameraMdel;
UINavigationController *nav=[[UINavigationController alloc] initWithRootViewController:monitorVC];
UIApplication*app=[UIApplication sharedApplication];
AppDelegate*app1=(AppDelegate*)app.delegate;
app1.window.rootViewController=nav;
//
[[IfishUserObsever sharedInstance] xinZengJingYanZhi:IFISHADDEXP_BIDCAMERA addType:IFISHADDEXPTYPE1];
});
}
} failure:^(NSError *err) {
}];
}
#pragma mark
-(void)bindDeviceWithSsid:(NSString*)bssid{
NSLog(@"设备bssid_%@",bssid);
@ -1171,9 +1627,6 @@ extern BOOL isfromCameraView;
self.navigationController.navigationBarHidden=NO;
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:Noti_WillEnterForeground object:nil];
}
@end