摄像头增加AP配网模式,bug修改,bugly id修改
摄像头增加AP配网模式,bug修改,bugly id修改 其他页面修改,细节处理
This commit is contained in:
+5
-2
@@ -17,7 +17,9 @@
|
||||
enum
|
||||
{
|
||||
conectType_Intelligent,
|
||||
conectType_qrcode
|
||||
conectType_qrcode,
|
||||
conectType_ap
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -26,6 +28,7 @@ enum
|
||||
@interface YooseeNextConnectViewController : BaseViewController
|
||||
@property (nonatomic,strong) NSString *uuidString;
|
||||
@property (nonatomic,strong) NSString *wifiPwd;
|
||||
@property (nonatomic,strong) NSString *wifiName;
|
||||
@property (strong, nonatomic) GCDAsyncUdpSocket *socket;
|
||||
@property (nonatomic) BOOL isWaiting;//YES表示发包设置wifi后,在等待局域网添加设备
|
||||
@property (nonatomic) BOOL isFinish;
|
||||
@@ -37,7 +40,7 @@ enum
|
||||
@property(nonatomic,strong) UITextField *wifiSecFiled;
|
||||
|
||||
@property(nonatomic,strong) UILabel *redTipLable;
|
||||
@property (nonatomic) int conectType; //1-二维码扫描 0-智能联机
|
||||
@property (nonatomic) int conectType; //2AP 1-二维码扫描 0-智能联机
|
||||
|
||||
@property (strong, nonatomic) NSString *lastSetPassword;
|
||||
//点击确定绑定后 不让操作返回 和查看说明
|
||||
|
||||
+150
-71
@@ -37,13 +37,12 @@ typedef NS_ENUM(NSInteger,lodingViewdissMissStyle) {
|
||||
lodingViewdissMissAlreadyBinded
|
||||
};
|
||||
|
||||
@interface YooseeNextConnectViewController ()<UITextFieldDelegate,UIAlertViewDelegate>
|
||||
@interface YooseeNextConnectViewController ()<UITextFieldDelegate,UIAlertViewDelegate,GWPP2PDeviceLinkerProtocol>
|
||||
{
|
||||
void *_context;
|
||||
}
|
||||
|
||||
@property (strong,nonatomic) NSMutableDictionary *addresses;
|
||||
@property (nonatomic,copy) NSString *wifiName;
|
||||
@property (nonatomic,strong) UIButton *sBtn;
|
||||
@property(nonatomic)BOOL autodismiss;
|
||||
@property(nonatomic,assign)lodingViewdissMissStyle lodviewMissStyle;
|
||||
@@ -66,7 +65,8 @@ typedef NS_ENUM(NSInteger,lodingViewdissMissStyle) {
|
||||
[super viewDidLoad];
|
||||
//智能联机
|
||||
self.isDeviceLinkIn = NO;
|
||||
self.conectType = conectType_Intelligent;
|
||||
[GWP2PDeviceLinker shareInstance].delegate=self;
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewWillEnterForeground:) name:Noti_WillEnterForeground object:nil];
|
||||
self.addresses = [[NSMutableDictionary alloc] initWithCapacity:1];
|
||||
self.view.backgroundColor = [UIColor whiteColor];
|
||||
[self addTitleViewWithTitle:@"连接摄像头"];
|
||||
@@ -76,6 +76,13 @@ typedef NS_ENUM(NSInteger,lodingViewdissMissStyle) {
|
||||
_canDissMissController = YES;
|
||||
//添加警告内容
|
||||
[self redTipLable];
|
||||
|
||||
if (self.conectType==conectType_ap&&self.wifiPwd.length&&self.wifiPwd.length)
|
||||
{
|
||||
[self connectNotNormalView];
|
||||
_canDissMissController = NO;
|
||||
[self apLinkConnect];
|
||||
}
|
||||
}
|
||||
|
||||
-(UILabel *)redTipLable{
|
||||
@@ -141,7 +148,11 @@ typedef NS_ENUM(NSInteger,lodingViewdissMissStyle) {
|
||||
|
||||
self.wifilabel=[[UILabel alloc] init];
|
||||
NSDictionary *ifs = [self fetchSSIDInfo];
|
||||
self.wifiName = [ifs objectForKey:@"SSID"];
|
||||
if (!self.wifiName.length)
|
||||
{
|
||||
self.wifiName = [ifs objectForKey:@"SSID"];
|
||||
}
|
||||
|
||||
|
||||
self.wifilabel.text = [NSString stringWithFormat:@"请输入当前WiFi:%@密码",self.wifiName];
|
||||
self.wifilabel.textAlignment = NSTextAlignmentLeft;
|
||||
@@ -269,7 +280,7 @@ typedef NS_ENUM(NSInteger,lodingViewdissMissStyle) {
|
||||
[alert show];
|
||||
return;
|
||||
}
|
||||
UIAlertView *alert= [[UIAlertView alloc] initWithTitle:@"提示" message:@"即将使用声波连接,请调大手机音量,并靠近设备,在听到“等待连接“后再点击确认" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
|
||||
UIAlertView *alert= [[UIAlertView alloc] initWithTitle:@"提示" message:@"即将使用声波连接,请调大手机音量,并靠近设备,确认设备已经重置(按复位小孔,听到“等待连接“或者“滴”)后再点击确认" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
|
||||
alert.tag = ALERT_TAG_B_SURE;
|
||||
|
||||
[alert show];
|
||||
@@ -318,9 +329,27 @@ typedef NS_ENUM(NSInteger,lodingViewdissMissStyle) {
|
||||
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{
|
||||
|
||||
|
||||
@@ -352,82 +381,131 @@ typedef NS_ENUM(NSInteger,lodingViewdissMissStyle) {
|
||||
_canDissMissController = NO;
|
||||
[self savePassw];
|
||||
//声波智能联机
|
||||
[self smartLinkConnect];
|
||||
if (self.conectType==conectType_Intelligent)
|
||||
{
|
||||
[self smartLinkConnect];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self apLinkConnect];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-(void)deviceLinkin:(NSDictionary*)deviceDict linkType:(NSInteger)type
|
||||
{
|
||||
NSLog(@"声波配网成功,返回数据:%@",deviceDict);
|
||||
if (self.isDeviceLinkIn) {
|
||||
return;
|
||||
}
|
||||
NSString *deviceID = [deviceDict[@"deviceID"] stringValue];
|
||||
NSString *deviceIP = deviceDict[@"deviceIP"];
|
||||
//AP配网时有值 smart没有值
|
||||
if ([self.deviceID isEqualToString:deviceID]||self.deviceID==nil)
|
||||
{
|
||||
self.isDeviceLinkIn = YES;
|
||||
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 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];//初始化密码
|
||||
[self bindCameraDevice];
|
||||
}];
|
||||
}else{//如果已经设置过初始密码,则直接使用
|
||||
[self bindCameraDevice];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
-(void)deviceLinkinTimeout:(NSInteger)type
|
||||
{
|
||||
//
|
||||
if (!self.isDeviceLinkIn) {//90秒之后还未连接上,连接超时
|
||||
|
||||
[[GWP2PDeviceLinker shareInstance] p2pStopAPLink];
|
||||
[self connectNormalView];
|
||||
if ([[[CommonUtils getSSIDInfo] objectForKey:@"SSID"] isEqualToString:self.wifiName])
|
||||
{
|
||||
[self.view makeToast:[NSString stringWithFormat:@"请确认手机已经连接到%@",self.wifiName]];
|
||||
}
|
||||
else
|
||||
{
|
||||
[self.view makeToast:@"WiFi连接失败"];
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
-(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]];
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
|
||||
|
||||
if([[UIApplication sharedApplication] canOpenURL:url]) {
|
||||
if (@available(iOS 10.0, *)) {
|
||||
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
|
||||
}else {
|
||||
[[UIApplication sharedApplication] openURL:url];
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
[weakSelf.view makeToast:@"该设备不支持AP配网"];
|
||||
}
|
||||
|
||||
|
||||
} deviceLinkIn:^(NSDictionary *deviceDict) {
|
||||
|
||||
[weakSelf deviceLinkin:deviceDict linkType:weakSelf.conectType];
|
||||
}];
|
||||
|
||||
|
||||
}
|
||||
//智能联机
|
||||
-(void)smartLinkConnect{
|
||||
WEAK_SELF;
|
||||
[[GWP2PDeviceLinker shareInstance] p2pStopSmartLink];
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(90 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
//
|
||||
if (!self.isDeviceLinkIn) {//90秒之后还未连接上,连接超时
|
||||
[[GWP2PDeviceLinker shareInstance] p2pStopSmartLink];
|
||||
[self connectNormalView];
|
||||
[self.view makeToast:@"WiFi连接失败"];
|
||||
}
|
||||
[self deviceLinkinTimeout:self.conectType];
|
||||
});
|
||||
[[GWP2PDeviceLinker shareInstance] p2pSmartLinkDeviceWithWiFiSSID:weakSelf.wifiName password:weakSelf.wifiPwd useSimpleConfig:YES deviceLinkIn:^(NSDictionary *deviceDict) {
|
||||
NSLog(@"声波配网成功,返回数据:%@",deviceDict);
|
||||
if (weakSelf.isDeviceLinkIn) {
|
||||
return;
|
||||
}
|
||||
weakSelf.isDeviceLinkIn = YES;
|
||||
[self.view makeToast:@"声波配网成功"];
|
||||
//如果智能联机,设备配网成功,就断开发送智能联机
|
||||
[[GWP2PDeviceLinker shareInstance] p2pStopSmartLink];
|
||||
NSString *deviceID = [deviceDict[@"deviceID"] stringValue];
|
||||
NSString *deviceIP = deviceDict[@"deviceIP"];
|
||||
// NSString *devicePassword = deviceDict[@"devicePassword"];
|
||||
weakSelf.deviceID = deviceID;
|
||||
[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);
|
||||
[weakSelf resetPassWord];//初始化密码
|
||||
[weakSelf bindCameraDevice];
|
||||
}];
|
||||
}else{//如果已经设置过初始密码,则直接使用
|
||||
[weakSelf bindCameraDevice];
|
||||
}
|
||||
// else{
|
||||
// [[GWP2PClient sharedClient] getMultipleDeviceStatusWithDeviceID:deviceIP password:@"123" completionBlock:^(GWP2PClient *client, BOOL success, NSDictionary<NSString *,id> *dataDictionary) {
|
||||
// NSLog(@"success:%i %@",success,dataDictionary);
|
||||
// [weakSelf resetPassWord];//更新密码
|
||||
// [weakSelf bindCameraDevice];
|
||||
//
|
||||
// }];
|
||||
// }
|
||||
// else {
|
||||
// //设备已经初始化过密码,则直接获取设备信息
|
||||
// [[GWP2PClient sharedClient] getMultipleDeviceStatusWithDeviceID:deviceIP password:devicePassword completionBlock:^(GWP2PClient *client, BOOL success, NSDictionary<NSString *,id> *dataDictionary) {
|
||||
// NSLog(@"success:%i %@",success,dataDictionary);
|
||||
// [weakSelf resetPassWord];//更新密码
|
||||
// if (success) {
|
||||
// dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// //[self.view makeToast:NSLocalizedString(@"operator_success", nil)];
|
||||
// dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
// usleep(800000);
|
||||
// dispatch_async(dispatch_get_main_queue(), ^{
|
||||
//
|
||||
// [weakSelf ifishUserBindcameraIdBy:self.contactID];
|
||||
//
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
// }else{
|
||||
// dispatch_async(dispatch_get_main_queue(), ^{
|
||||
//
|
||||
// self.lodviewMissStyle =lodingViewdissMissSuccsess;
|
||||
// [self connectNormalView];
|
||||
// _canDissMissController = YES;
|
||||
// [self.view makeToast:NSLocalizedString(@"operator_failure", nil)];
|
||||
//
|
||||
// });
|
||||
// }
|
||||
// }];
|
||||
// }
|
||||
[weakSelf deviceLinkin:deviceDict linkType:weakSelf.conectType];
|
||||
}];
|
||||
}
|
||||
//初始化设备密码回调
|
||||
@@ -465,6 +543,7 @@ typedef NS_ENUM(NSInteger,lodingViewdissMissStyle) {
|
||||
|
||||
-(void)dealloc{
|
||||
[[GWP2PDeviceLinker shareInstance] p2pStopSmartLink];
|
||||
[[GWP2PDeviceLinker shareInstance] p2pStopAPLink];
|
||||
|
||||
}
|
||||
#pragma mark - UI正常状态
|
||||
|
||||
Reference in New Issue
Block a user