947 lines
35 KiB
Plaintext
947 lines
35 KiB
Plaintext
//
|
|
// YooseeNextConnectViewController.m
|
|
// IfihYooeeDemo
|
|
//
|
|
// Created by imac on 16/5/31.
|
|
// Copyright © 2016年 xiang. All rights reserved.
|
|
//
|
|
|
|
#import "YooseeNextConnectViewController.h"
|
|
#import "WaitingPageView.h"
|
|
#define WAITING_CONTENT_VIEW_HEIGHT 300
|
|
#define NAVIGATION_BAR_HEIGHT ([[[UIDevice currentDevice] systemVersion] floatValue] < 7.0 ? (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? 44:44):(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ? 64:64))
|
|
#import <SystemConfiguration/CaptiveNetwork.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 YooseeNextConnectViewController ()<UITextFieldDelegate,UIAlertViewDelegate,GWPP2PDeviceLinkerProtocol>
|
|
{
|
|
void *_context;
|
|
}
|
|
|
|
@property (strong,nonatomic) NSMutableDictionary *addresses;
|
|
@property (strong,nonatomic) NSMutableDictionary *linkDict;
|
|
@property (nonatomic,strong) UIButton *sBtn;
|
|
@property(nonatomic)BOOL autodismiss;
|
|
@property(nonatomic,assign)lodingViewdissMissStyle lodviewMissStyle;
|
|
@property(nonatomic,retain) NSTimer* getInfTimer ;
|
|
|
|
@property(nonatomic,strong) UILabel *wifilabel;
|
|
|
|
@property(nonatomic,strong) UIImageView *nodImg;
|
|
@property(nonatomic,strong) LXWaveProgressView *waveProgressView;;
|
|
@property(nonatomic,strong) IfishConnectingView *connectingView;
|
|
|
|
@property (copy, nonatomic) NSString *deviceID;//设备id
|
|
@property (assign, nonatomic) BOOL isDeviceLinkIn;//是否已经连接智能设备
|
|
|
|
@end
|
|
|
|
@implementation YooseeNextConnectViewController
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
//智能联机
|
|
self.isDeviceLinkIn = NO;
|
|
[GWP2PDeviceLinker shareInstance].delegate=self;
|
|
self.deviceID=nil;
|
|
//[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewWillEnterForeground:) name:Noti_WillEnterForeground object:nil];
|
|
self.addresses = [[NSMutableDictionary alloc] initWithCapacity:1];
|
|
self.linkDict = [[NSMutableDictionary alloc] initWithCapacity:1];
|
|
self.view.backgroundColor = [UIColor whiteColor];
|
|
[self addTitleViewWithTitle:@"连接摄像头"];
|
|
[self initComponent];
|
|
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
|
|
self.navigationItem.backBarButtonItem = item;
|
|
_canDissMissController = YES;
|
|
//添加警告内容
|
|
[self redTipLable];
|
|
// [self tipsLabelAndButton];
|
|
|
|
if (self.conectType==conectType_ap&&self.wifiPwd.length&&self.wifiPwd.length)
|
|
{
|
|
[self connectNotNormalView];
|
|
_canDissMissController = NO;
|
|
[self apLinkConnect];
|
|
}
|
|
}
|
|
|
|
-(UILabel *)redTipLable{
|
|
if (_redTipLable==nil) {
|
|
CGFloat y = CGRectGetMaxY(self.wifiSecFiled.frame) + 5;
|
|
_redTipLable=[[UILabel alloc]initWithFrame:CGRectMake(19, y, 100, 10)];
|
|
_redTipLable.text=@"(暂不支持5G网络,请使用2.4G网络)";
|
|
_redTipLable.font=[UIFont systemFontOfSize:13];
|
|
_redTipLable.textColor=[UIColor redColor];
|
|
[_redTipLable sizeToFit];
|
|
[self.view addSubview:_redTipLable];
|
|
[self.view bringSubviewToFront:_redTipLable];
|
|
}
|
|
return _redTipLable;
|
|
}
|
|
-(void)tipsLabelAndButton
|
|
{
|
|
CGFloat y = CGRectGetMaxY(self.redTipLable.frame) + 5;
|
|
UILabel* tipLable=[[UILabel alloc]initWithFrame:CGRectMake(19, y, 100, 10)];
|
|
tipLable.text=@"(如有问题,请尝试热点连接模式)";
|
|
tipLable.font=[UIFont systemFontOfSize:13];
|
|
tipLable.textColor=[UIColor lightGrayColor];
|
|
[tipLable sizeToFit];
|
|
[self.view addSubview:tipLable];
|
|
[self.view bringSubviewToFront:tipLable];
|
|
|
|
UIButton*button=[UIButton buttonWithType:UIButtonTypeCustom];
|
|
button.frame=CGRectMake(CGRectGetMaxX(tipLable.frame), CGRectGetMinY(tipLable.frame), 60, 10);
|
|
button.titleLabel.font=[UIFont systemFontOfSize:13];
|
|
[button setTitle:@"点击这里" forState:UIControlStateNormal];
|
|
[button setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
|
|
[button addTarget:self action:@selector(goAPmode) forControlEvents:UIControlEventTouchUpInside];
|
|
[self.view addSubview:button];
|
|
|
|
}
|
|
//获取WiFi信息
|
|
- (id)fetchSSIDInfo
|
|
{
|
|
NSArray *ifs = (id)CFBridgingRelease(CNCopySupportedInterfaces());
|
|
NSLog(@"%s: Supported interfaces: %@", __func__, ifs);
|
|
id info = nil;
|
|
for (NSString *ifnam in ifs) {
|
|
info = (id)CFBridgingRelease(CNCopyCurrentNetworkInfo((CFStringRef)ifnam));
|
|
if (info && [info count]) {
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
return info ;
|
|
}
|
|
|
|
-(void)viewWillDisappear:(BOOL)animated{
|
|
[super viewWillDisappear:animated];
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self name:UITextFieldTextDidChangeNotification object:self.wifiSecFiled];
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
|
|
|
|
[[GWP2PDeviceLinker shareInstance] p2pStopSmartLink];
|
|
}
|
|
|
|
-(void)viewWillAppear:(BOOL)animated{
|
|
[super viewWillAppear:animated];
|
|
}
|
|
-(void)viewDidAppear:(BOOL)animated{
|
|
[super viewDidAppear:animated];
|
|
|
|
}
|
|
- (void)didReceiveMemoryWarning {
|
|
[super didReceiveMemoryWarning];
|
|
// Dispose of any resources that can be recreated.
|
|
}
|
|
-(void)initComponent{
|
|
//967/1018/ 0.95
|
|
|
|
CGFloat percentHbiW = 0.117 ;//5s 35/300
|
|
CGFloat y = 20;
|
|
self.nodImg= [[UIImageView alloc] initWithFrame:CGRectMake(5, y,12, 12)];
|
|
self.nodImg.image = [UIImage imageNamed:@"linkingdevice_point"];
|
|
[self.view addSubview:self.nodImg];
|
|
|
|
|
|
self.wifilabel=[[UILabel alloc] init];
|
|
NSDictionary *ifs = [self fetchSSIDInfo];
|
|
if (!self.wifiName.length)
|
|
{
|
|
self.wifiName = [ifs objectForKey:@"SSID"];
|
|
}
|
|
|
|
|
|
self.wifilabel.text = [NSString stringWithFormat:@"请输入当前WiFi:%@密码",self.wifiName];
|
|
self.wifilabel.textAlignment = NSTextAlignmentLeft;
|
|
|
|
self.wifilabel.textColor = [UIColor colorWithRed:153.0/255.0 green:153.0/255.0 blue:153.0/255.0 alpha:1];
|
|
NSMutableAttributedString * attributedString = [[NSMutableAttributedString alloc] initWithString:self.wifilabel.text];
|
|
NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
|
|
[paragraphStyle setLineSpacing:8];
|
|
[attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [self.wifilabel.text length])];
|
|
[attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:0 green:170.0/255.0 blue:218.0/255.0 alpha:1] range:NSMakeRange(10,self.wifiName.length)];
|
|
[self.wifilabel setAttributedText:attributedString];
|
|
[self.wifilabel sizeToFit];
|
|
|
|
CGFloat labelSizeW = [self widthForString:self.wifilabel.text fontSize:18 andHeight:10];
|
|
CGFloat labelH= [self heightForString:self.wifilabel.text fontSize:18 andWidth:labelSizeW];
|
|
|
|
self.wifilabel.frame = CGRectMake(CGRectGetMaxX(self.nodImg.frame), y, labelSizeW, labelH);
|
|
|
|
[self.view addSubview:self.wifilabel];
|
|
//wifi 输入框
|
|
CGFloat wifiFileW=kScreenSize.width - 2*10;
|
|
CGFloat wifiFileH=wifiFileW*percentHbiW;
|
|
|
|
self.wifiSecFiled=[[UITextField alloc] initWithFrame:CGRectMake(10,CGRectGetMaxY(self.wifilabel.frame) + 10, wifiFileW, wifiFileH)];
|
|
|
|
self.wifiSecFiled.placeholder = @"请输入WiFi密码";
|
|
self.wifiSecFiled.delegate=self;
|
|
self.wifiSecFiled.keyboardType=UIKeyboardTypeAlphabet;
|
|
self.wifiSecFiled.layer.masksToBounds=YES;
|
|
self.wifiSecFiled.layer.cornerRadius=5;
|
|
if (@available(iOS 13.0, *)){//iOS13之后,设置颜色的方便变更
|
|
|
|
}else{
|
|
[self.wifiSecFiled setValue:[UIColor colorWithRed:153.0/255.0 green:153.0/255.0 blue:153.0/255.0 alpha:1] forKeyPath:@"_placeholderLabel.textColor"];
|
|
}
|
|
self.wifiSecFiled.borderStyle = UITextBorderStyleNone;
|
|
self.wifiSecFiled.backgroundColor = [UIColor colorWithRed:244.0/255.0 green:244.0/255.0 blue:244.0/255.0 alpha:1];
|
|
NSUserDefaults*userDefsult=[NSUserDefaults standardUserDefaults];
|
|
NSString*pass=[userDefsult objectForKey:@"wifiPass"];
|
|
|
|
if (pass) {
|
|
self.wifiSecFiled.text = pass;
|
|
}
|
|
self.wifiSecFiled.textAlignment = NSTextAlignmentLeft;
|
|
|
|
[self.view addSubview:self.wifiSecFiled];
|
|
|
|
//占位view 让输入框文字 偏移 也有别的方法 contentoffset
|
|
UIView*phoneView=[[UIView alloc]initWithFrame:CGRectMake(0,0, 9, 10)];
|
|
self.wifiSecFiled.leftView=phoneView;
|
|
self.wifiSecFiled.leftViewMode=UITextFieldViewModeAlways;
|
|
|
|
CGFloat btnW=100;
|
|
//输入框内白色2像素view
|
|
UIView *whiteView=[[UIView alloc] initWithFrame:CGRectMake(wifiFileW - btnW -2, 0, 2, wifiFileH)];
|
|
whiteView.backgroundColor = [UIColor whiteColor];
|
|
|
|
[self.wifiSecFiled addSubview:whiteView];
|
|
|
|
|
|
self.sBtn=[UIButton buttonWithType:UIButtonTypeCustom];
|
|
[self.sBtn setTitle:@"确定" forState:UIControlStateNormal];
|
|
|
|
self.sBtn.frame = CGRectMake(wifiFileW - btnW,0, btnW,wifiFileH);
|
|
|
|
[self.sBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
|
[self.sBtn addTarget:self action:@selector(sBtn:) forControlEvents:UIControlEventTouchUpInside];
|
|
//self.sBtn.backgroundColor = COLOR_LABEL_TITLE;
|
|
[self.sBtn setBackgroundImage:[UIImage imageNamed:@"linkingdevice_botton"] forState:UIControlStateNormal];
|
|
[self.wifiSecFiled addSubview:self.sBtn];
|
|
|
|
//底部背景
|
|
UIImageView *backImg=[[UIImageView alloc] initWithFrame:CGRectMake(0,kScreenSize.height - kScreenSize.width * 1.1,kScreenSize.width,kScreenSize.width * 1.1)];
|
|
backImg.image = [UIImage imageNamed:@"linkingdevice_setting"];
|
|
backImg.userInteractionEnabled = YES;
|
|
|
|
[self.view addSubview:backImg];
|
|
|
|
|
|
//波纹
|
|
self.waveProgressView = [[LXWaveProgressView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.wifiSecFiled.frame) +10, kScreenSize.width,CGRectGetMinY(backImg.frame) - CGRectGetMaxY(self.wifiSecFiled.frame))];
|
|
|
|
self.attentionLabel=[[UILabel alloc]initWithFrame:CGRectMake(30, CGRectGetMidY(self.waveProgressView.frame), kScreenWidth-60, 130)];
|
|
self.attentionLabel.font=[UIFont systemFontOfSize:13];
|
|
self.attentionLabel.textColor=[UIColor blackColor];
|
|
self.attentionLabel.numberOfLines=0;
|
|
self.attentionLabel.text=@"1、请长按摄像头背后复位孔,复位摄像头。\n2、若Wifi名称有中文,请改成英文字母加数字。\n3、Wifi密码不能包含特殊符号(如‘“等)。\n4、若多次智能连接未成功,请尝试热点模式连接。";
|
|
[self.view addSubview:self.waveProgressView];
|
|
[self.view bringSubviewToFront:self.waveProgressView];
|
|
[self.view addSubview:self.attentionLabel];
|
|
|
|
|
|
|
|
//说明书
|
|
UIButton *shuimingshuBtn=[UIButton buttonWithType:UIButtonTypeCustom];
|
|
shuimingshuBtn.frame = CGRectMake(0,kScreenSize.height - 44 - 200, kScreenSize.width*1/3, 200);
|
|
[shuimingshuBtn addTarget:self action:@selector(ChaKanShuimingShu) forControlEvents:UIControlEventTouchUpInside];
|
|
//[shuimingshuBtn setBackgroundColor:[UIColor redColor]];
|
|
[self.view addSubview:shuimingshuBtn];
|
|
|
|
//设置输入状态UI
|
|
[self connectNormalView];
|
|
|
|
|
|
}
|
|
|
|
#pragma mark - ChaKanShuimingShu
|
|
|
|
-(void)ChaKanShuimingShu{
|
|
|
|
if (!_canDissMissController ) {
|
|
|
|
[self.view makeToast:@"正在连接中请稍后操作"];
|
|
return;
|
|
|
|
}
|
|
|
|
// PushMasssageWebViewController*webVC=[[PushMasssageWebViewController alloc]init];
|
|
// webVC.pushlink =IFISH_DEVCEITROURL;
|
|
// webVC.pushtitle = NSLocalizedString(@"ifish_deviceuse", nil);;
|
|
//
|
|
// [self.navigationController pushViewController:webVC animated:YES];
|
|
|
|
InfoByImageViewController*info=[[InfoByImageViewController alloc]init];
|
|
info.title=NSLocalizedString(@"ifish_deviceuse", nil);;;
|
|
info.type=@"instruction";
|
|
info.image=[UIImage imageNamed:@"instruction"];
|
|
[self.navigationController pushViewController:info animated:YES];
|
|
|
|
|
|
}
|
|
|
|
|
|
#pragma mark- 点击确定
|
|
-(void)goAPmode
|
|
{
|
|
ConAquarNowWiFiPwdVC *vc = InitObject(ConAquarNowWiFiPwdVC);
|
|
vc.deviceType=DEVICECAMERA;
|
|
NSDictionary *netInfo = [CommonUtils getSSIDInfo];
|
|
vc.ssid = [netInfo objectForKey:@"SSID"];
|
|
vc.bssid = [netInfo objectForKey:@"BSSID"];
|
|
|
|
|
|
[self.navigationController pushViewController:vc animated:YES];
|
|
}
|
|
-(void)sBtn:(UIButton*)btn{
|
|
NSString *ssidName =@"";
|
|
if (self.wifiName.length>2) {
|
|
ssidName= [self.wifiName substringWithRange:NSMakeRange(self.wifiName.length-2, 2)];
|
|
}
|
|
|
|
if ([ssidName.uppercaseString isEqualToString:@"5G"]) {
|
|
UIAlertView *alert= [[UIAlertView alloc] initWithTitle:@"" message:@"仅支持2.4G WI-Fi网络,请重新选择" delegate:nil cancelButtonTitle:@"去更改" otherButtonTitles:nil, nil];
|
|
[alert show];
|
|
return;
|
|
}
|
|
if ([self.wifiName.uppercaseString isEqualToString:@"WLAN"]) {
|
|
UIAlertView *alert= [[UIAlertView alloc] initWithTitle:@"" message:@"获取到的WiFi无效" delegate:nil cancelButtonTitle:@"重试" otherButtonTitles:nil, nil];
|
|
alert.tag=3;
|
|
[alert show];
|
|
return;
|
|
}
|
|
BOOL isRight =[dataContorl isIncludeSpecialCharact:self.wifiSecFiled.text];
|
|
|
|
if (!isRight) {
|
|
[self.view makeToast:@"您输入的密码带特殊符号,请更改路由器密码。"];
|
|
return;
|
|
}
|
|
UIAlertView *alert= [[UIAlertView alloc] initWithTitle:@"提示" message:@"即将使用声波连接,请调大手机音量,并靠近设备,确认设备已经重置(按复位小孔,听到“等待连接“或者“滴”)后再点击确认" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
|
|
alert.tag = ALERT_TAG_B_SURE;
|
|
|
|
[alert show];
|
|
|
|
|
|
}
|
|
-(void)showTitle:(NSString*)title messsage:(NSString*)message{
|
|
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:title message:message delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];
|
|
NSTimeInterval dismissSeconds=1.0;
|
|
[alert show];
|
|
[self performSelector:@selector(dismissAlert:) withObject:alert afterDelay:dismissSeconds];
|
|
|
|
}
|
|
|
|
-(void)dismissAlert:(UIAlertView*)alertView{
|
|
|
|
[alertView dismissWithClickedButtonIndex:[alertView cancelButtonIndex] animated:YES];
|
|
}
|
|
|
|
|
|
//保存wifi密码
|
|
-(void)savePassw{
|
|
NSUserDefaults*userdefult=[NSUserDefaults standardUserDefaults];
|
|
|
|
[userdefult setObject:self.wifiSecFiled.text forKey:@"wifiPass"];
|
|
[userdefult synchronize];
|
|
}
|
|
|
|
#pragma -mark -functions
|
|
|
|
//获取字符串的宽度
|
|
-(float) widthForString:(NSString *)value fontSize:(float)fontSize andHeight:(float)height
|
|
{
|
|
CGSize sizeToFit = [value sizeWithFont:[UIFont systemFontOfSize:fontSize] constrainedToSize:CGSizeMake(CGFLOAT_MAX, height) lineBreakMode:NSLineBreakByWordWrapping];//此处的换行类型(lineBreakMode)可根据自己的实际情况进行设置
|
|
return sizeToFit.width;
|
|
}
|
|
//获得字符串的高度
|
|
-(float) heightForString:(NSString *)value fontSize:(float)fontSize andWidth:(float)width
|
|
{
|
|
CGSize sizeToFit = [value sizeWithFont:[UIFont systemFontOfSize:fontSize] constrainedToSize:CGSizeMake(width, CGFLOAT_MAX) lineBreakMode:NSLineBreakByCharWrapping];//此处的换行类型(lineBreakMode)可根据自己的实际情况进行设置
|
|
return sizeToFit.height;
|
|
}
|
|
//密码
|
|
-(void)resetPassWord{
|
|
|
|
NSString *newPassword = GIWEI_INITPASS;
|
|
self.lastSetPassword = [Utils GetTreatedPassword:newPassword];
|
|
}
|
|
#pragma mark---到前台,搜索设备
|
|
//-(void)viewWillEnterForeground:(NSNotification *)noti{
|
|
//
|
|
// if (self.deviceID.length&&!self.isDeviceLinkIn)
|
|
// {
|
|
// [GWP2PDeviceLinker shareInstance].delegate=self;
|
|
// [[GWP2PDeviceLinker shareInstance] forceScanLanDevices];
|
|
// }
|
|
//}
|
|
|
|
#pragma mark - 搜索到设备,弹出添加设备提示 暂不用
|
|
/**
|
|
局域网里面有设备联网成功后,都会回调此方法。UDP使用
|
|
|
|
@param deviceDict 设备信息
|
|
*/
|
|
- (void)p2pDeviceLinker:(GWP2PDeviceLinker *)linker deviceLinkSuccess:(NSDictionary *)deviceDict
|
|
{
|
|
NSLog(@"扫描到设备");
|
|
[self deviceLinkin:deviceDict linkType:self.conectType];
|
|
}
|
|
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
|
|
|
|
|
|
if (alertView.tag==ALERT_TAG_SET_FAILED) {
|
|
|
|
if(buttonIndex==0){
|
|
|
|
}
|
|
}else if (alertView.tag==ALERT_TAG_B_SURE){
|
|
|
|
if (buttonIndex ==1) {
|
|
|
|
[self.wifiSecFiled resignFirstResponder];
|
|
|
|
if (self.wifiSecFiled.text.length<=0||[self.wifiName isEqualToString:@"无Wi-Fi"]) {
|
|
[self.view makeToast:@"请保证手机已连接wifi,且wifi密码不能为空"];
|
|
return;
|
|
}
|
|
|
|
if (!self.wifiName) {
|
|
|
|
[self.view makeToast:@"未检测到wifi"];
|
|
|
|
return;
|
|
}
|
|
self.wifiPwd = self.wifiSecFiled.text;
|
|
//显示连接中效果
|
|
[self connectNotNormalView];
|
|
_canDissMissController = NO;
|
|
[self savePassw];
|
|
//声波智能联机
|
|
if (self.conectType==conectType_Intelligent)
|
|
{
|
|
[self smartLinkConnect];
|
|
}
|
|
else
|
|
{
|
|
[self apLinkConnect];
|
|
}
|
|
|
|
}
|
|
}//重试wifi
|
|
else if (alertView.tag==3){
|
|
|
|
[self initComponent];
|
|
}
|
|
}
|
|
|
|
-(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秒之后还未连接上,连接超时
|
|
[[GWP2PDeviceLinker shareInstance] p2pStopSmartLink];
|
|
[[GWP2PDeviceLinker shareInstance] p2pStopAPLink];
|
|
|
|
if ([[[CommonUtils getSSIDInfo] objectForKey:@"SSID"] isEqualToString:self.wifiName])
|
|
{
|
|
[self.view makeToast:@"请确保Wifi密码正确,重置设备后再试!"];
|
|
}
|
|
else
|
|
{
|
|
[self.view makeToast:[NSString stringWithFormat:@"WiFi连接失败,请确保手机连接到%@",self.wifiName]];
|
|
}
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|
|
|
[self.navigationController popViewControllerAnimated:YES];
|
|
});
|
|
|
|
}
|
|
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.conectType];
|
|
});
|
|
|
|
[self resetPassWord];//初始化密码
|
|
[[GWP2PDeviceLinker shareInstance] p2pAPLinkDeviceWithWiFiSSID:weakSelf.wifiName wifiPassword:weakSelf.wifiPwd devicePassword:weakSelf.lastSetPassword deviceReceive:^(NSString *deviceId, BOOL isSupport) {
|
|
|
|
|
|
|
|
if (isSupport)
|
|
{
|
|
|
|
weakSelf.deviceID=deviceId;
|
|
[weakSelf.view makeToast:[NSString stringWithFormat:@"设备即将连接网络,请将手机自动重新连接到%@",weakSelf.wifiName]];
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
[weakSelf.view makeToast:@"该设备不支持AP配网"];
|
|
}
|
|
|
|
|
|
} deviceLinkIn:^(NSDictionary *deviceDict) {
|
|
|
|
[weakSelf deviceLinkin:deviceDict linkType:weakSelf.conectType];
|
|
}];
|
|
|
|
|
|
}
|
|
//智能联机
|
|
-(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.conectType];
|
|
});
|
|
[[GWP2PDeviceLinker shareInstance] p2pSmartLinkDeviceWithWiFiSSID:weakSelf.wifiName password:weakSelf.wifiPwd useSimpleConfig:YES deviceLinkIn:^(NSDictionary *deviceDict) {
|
|
[weakSelf deviceLinkin:deviceDict linkType:weakSelf.conectType];
|
|
}];
|
|
}
|
|
//初始化设备密码回调
|
|
-(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];
|
|
|
|
}
|
|
#pragma mark - UI正常状态
|
|
|
|
-(void)connectNormalView
|
|
{
|
|
|
|
if (!self.connectingView) {
|
|
CGFloat yOffset = 0;
|
|
if (is_iPhone_X) {
|
|
yOffset = 88;
|
|
} else {
|
|
yOffset = 64;
|
|
}
|
|
|
|
IfishConnectingView *connectingView=[[IfishConnectingView alloc] initWithFrame:CGRectMake(0,yOffset, kScreenSize.width, CGRectGetMaxY(self.wifiSecFiled.frame))];
|
|
self.connectingView =connectingView;
|
|
|
|
[self.connectingView.textChangeView animationWithTexts:[NSArray arrayWithObjects:@"正在拼命连接中...",@"请将摄像头放在wifi信号良好的位置",@"连接时,请开大手机音量",@"连接过程会持续40s左右,请耐心等待",@"连接不上,请点击下方说明书",nil]];
|
|
|
|
//self.connectingView.backgroundColor = [UIColor redColor];
|
|
|
|
[self.view addSubview:self.connectingView];
|
|
self.wifilabel.hidden = NO;
|
|
self.wifiSecFiled.hidden = NO;
|
|
self.sBtn.hidden = NO;
|
|
self.nodImg.hidden = NO;
|
|
self.redTipLable.hidden=NO;
|
|
|
|
self.connectingView.alpha = 0;
|
|
|
|
}else{
|
|
|
|
[UIView animateWithDuration:2.0 animations:^{
|
|
|
|
self.connectingView.alpha = 0;
|
|
|
|
|
|
} completion:^(BOOL finished) {
|
|
|
|
[self.connectingView.textChangeView stopAnimation];
|
|
self.wifilabel.hidden = NO;
|
|
self.wifiSecFiled.hidden = NO;
|
|
self.sBtn.hidden = NO;
|
|
self.nodImg.hidden = NO;
|
|
self.redTipLable.hidden=NO;
|
|
|
|
}];
|
|
}
|
|
}
|
|
|
|
#pragma mark - UI连接状态
|
|
|
|
-(void)connectNotNormalView{
|
|
|
|
|
|
[UIView animateWithDuration:2.0 animations:^{
|
|
|
|
self.connectingView.alpha = 1;
|
|
self.connectingView.lineView.alpha = 1;
|
|
self.connectingView.fishImageView.alpha = 1;
|
|
|
|
} completion:^(BOOL finished) {
|
|
|
|
[self.connectingView.textChangeView startTextAnimation];
|
|
|
|
|
|
}];
|
|
|
|
self.wifilabel.hidden = YES;
|
|
self.wifiSecFiled.hidden = YES;
|
|
self.sBtn.hidden = YES;
|
|
self.nodImg.hidden = YES;
|
|
self.redTipLable.hidden=YES;
|
|
self.attentionLabel.hidden=YES;
|
|
}
|
|
|
|
-(void)wifiviewkeyboardWillHide:(NSNotification *)notify{
|
|
|
|
// 键盘动画时间
|
|
double duration = [[notify.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
|
|
|
|
//视图下沉恢复原状
|
|
[UIView animateWithDuration:duration animations:^{
|
|
self.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
|
|
}];
|
|
|
|
}
|
|
|
|
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
-(void)wifiviewkeyboradWillShow:(NSNotification*)notification{
|
|
|
|
|
|
CGRect keyboardFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
|
|
|
|
CGRect buttonRect = [self.sBtn convertRect:self.sBtn.bounds toView:self.view];
|
|
|
|
CGFloat buttonMargin =(buttonRect.origin.y + buttonRect.size.height + 10);
|
|
|
|
CGFloat transformY = keyboardFrame.origin.y - buttonMargin;
|
|
// 取得键盘的动画时间,这样可以在视图上移的时候更连贯
|
|
double duration = [[notification.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
|
|
[UIView animateWithDuration:duration animations:^{
|
|
|
|
if (keyboardFrame.origin.y < self.view.frame.size.height) {
|
|
self.view.transform = CGAffineTransformMakeTranslation(0,transformY);
|
|
}else{
|
|
self.view.transform = CGAffineTransformMakeTranslation(0, 0);
|
|
}
|
|
}];
|
|
}
|
|
|
|
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
|
|
[textField resignFirstResponder];
|
|
|
|
return YES;
|
|
}
|
|
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
|
|
[self hiddenKeybord];
|
|
}
|
|
-(void)hiddenKeybord{
|
|
|
|
[self.wifiSecFiled resignFirstResponder];
|
|
}
|
|
|
|
|
|
#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;
|
|
_canDissMissController = YES;
|
|
//绑定成功之后,直接跳转详情页面
|
|
/**
|
|
存储摄像头设备信息
|
|
*/
|
|
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 connectNormalView];
|
|
_canDissMissController = YES;
|
|
[self.view makeToast:@"绑定失败错误码101"];
|
|
|
|
}
|
|
|
|
} failure:^(NSError *err) {
|
|
|
|
[self connectNormalView];
|
|
[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) {
|
|
}];
|
|
}
|
|
|
|
@end
|