ifish/Ifish/controllers/HotBar/IfishBaseVc.m

364 lines
10 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// IfishBaseVc.m
// Ifish
//
// Created by 罗艺 on 2018/9/23.
// Copyright © 2018年 lianlian. All rights reserved.
//
#import "IfishBaseVc.h"
#import "CreatErWeiMaController.h"
#import "JHRefreshAmazingAniView.h"
#import "UIScrollView+JHRefresh.h"
@interface IfishBaseVc ()<IfishCommuniteDelegate>
@end
@implementation IfishBaseVc
- (void)viewDidLoad {
[super viewDidLoad];
[self InitSocket];
[Socketsingleton sharedInstance].communiteDelegate=self;
// Do any additional setup after loading the view.
//右侧下拉菜单
[self initPopOver];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark--------
-(void)socketDidGetBackmsgData:(NSData *)data onsoket:(AsyncSocket *)sock{
}
//已断开连接
- (void)ifishSocketDidDisconnect:(AsyncSocket *)sock{
_isconnect=NO;
[self endRefreshing];
}
//已经连接成功
-(void)ifishSocket:(AsyncSocket *)sock ifishSocketdidConnectToHost:(NSString *)host port:(UInt16)port{
//已建立连接 登陆指令同意在soket单例中
_isconnect=YES;
}
//发送数据完成
- (void)ifishSocket:(AsyncSocket *)sock didWriteDataWithTag:(long)tag{}
//错误断开
-(void)ifishSocket:(AsyncSocket *)sock willDisconnectWithError:(NSError *)err{
}
// 将要连接
- (BOOL)ifishSocketWillConnect:(AsyncSocket *)sock{
return YES;
}
//新的soket
- (void)ifishSocket:(AsyncSocket *)sock didAcceptNewSocket:(AsyncSocket *)newSocket{}
//设备登陆成功
-(void)ifishDeviceLogInSuccees{}
//设备登陆失败
-(void)ifishDeviceLogInFail{}
- (void)showLableAction:(NSString *)str{
UILabel *laberAction =[[UILabel alloc]init];
laberAction.frame =CGRectMake((kScreenSize.width/2) - 50, kScreenSize.height/2 , 100, 50);
laberAction.clipsToBounds =YES;
laberAction.layer.cornerRadius =5;
laberAction.alpha =1;
laberAction.text =str;
laberAction.textAlignment =NSTextAlignmentCenter;
laberAction.backgroundColor =IndicatorBack_COLOR;
laberAction.font=[UIFont systemFontOfSize:12];
laberAction.textColor=[UIColor whiteColor];
[UIView animateWithDuration:2.0 animations:^{
laberAction.alpha =0;
}completion:^(BOOL finished) {
[laberAction removeFromSuperview];
}];
[self.view addSubview:laberAction];
}
-(void)InitSocket{
NSLog(@"******%d",[Socketsingleton sharedInstance].clientSocket.isConnected);
if (![Socketsingleton sharedInstance].clientSocket.isConnected) {
//[[Socketsingleton sharedInstance];
}
// 切换设备 先断开然后重连
[[Socketsingleton sharedInstance] socketConnectHost];
[Socketsingleton sharedInstance].macAddress = self.devicemodel.macAddress;
// if ([self.singletonSocket.clientSocket canSafelySetDelegate]==YES) {
// self.singletonSocket.clientSocket=[[AsyncSocket alloc]initWithDelegate:self];
// }else{
// NSLog(@"当前的委托有悬而未决的业务(读/写)");
// }
}
- (NSString *)zeroLeftPadding:(NSString *)origin {
if (origin.length >= 40) {
return [origin substringToIndex:40];
} else {
NSInteger left = 40 - origin.length;
NSMutableString *str = [NSMutableString string];
[str appendString:origin];
for (NSInteger index = 0; index < left; index++) {
[str appendString:@"0"];
}
return [str copy];
}
}
#pragma mark- 下拉菜单
-(MessageAlertView *)popView{
if (!_popView) {
_popView = [[MessageAlertView alloc]initWithFrame:RECT(screen_width - kSizeFrom750(220), 0, kSizeFrom750(220), kSizeFrom750(270))];
WEAK_SELF;
//点击
_popView.comboxBlock = ^(NSInteger tag) {
if (tag == 0) {
//修改名称
[weakSelf shezhiMingCheng];
}else if (tag == 1){
//删除设备
[weakSelf deletDevice];
}else if (tag == 2){
//分享设备
[weakSelf fenXiangSheBei];
}
[weakSelf presentPopView];//隐藏弹出框
};
}
return _popView;
}
//弹出分享框
-(void)presentPopView{
BOOL isHidden = self.popView.hidden;
if (isHidden) {
self.popView.hidden = NO;
}
[UIView animateWithDuration:0.3 animations:^{
self.popView.transform = CGAffineTransformScale(self.popView.transform,isHidden?100:0.01,isHidden?100:0.01);
} completion:^(BOOL finished) {
self.popView.hidden = !isHidden;
}];
}
-(void)initPopOver{
[self.view addSubview:self.popView];
NSArray *titleImgs =nil;
NSArray *titles=nil;
if ([self.devicemodel.isMaster isEqualToString:@"1"]) {
//主控
titleImgs = @[@"ifishdropview_edite_device",@"ifishdropview_delect_device",@"Ifish_share_device"];
titles=@[@"修改名称",@"删除设备",@"分享设备"];
}else{
titleImgs = @[@"ifishdropview_edite_device",@"ifishdropview_delect_device"];
titles=@[@"修改名称",@"删除设备"];
}
[self.popView loadInfoWithTitle:titles Icons:titleImgs];
}
#pragma mark - 修改设备名
-(void)shezhiMingCheng{
// self.setNameVC = [[SetNameTextViewController alloc] init];
//
// self.setNameVC.name = self.name.text;
// self.setNameVC.device = self.currentDevice;
// self.setNameVC.deviceType = 0;
//
// __weak typeof (self)wself = self;
// _setNameVC.NameWithBlock = ^(NSString *nameStr){
//
// wself.name.text = nameStr;
//
// };
//
//
// [ wself.navigationController pushViewController: wself.setNameVC animated:YES];
}
#pragma mark - 删除设备
-(void)deletDevice{
UIAlertController*ac=[UIAlertController alertControllerWithTitle:@"提示" message:@"确认删除设备?" preferredStyle:UIAlertControllerStyleAlert];
[self presentViewController:ac animated:YES completion:nil];
[ac addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction*action){
}]];
[ac addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction*action){
//先判断此设备是否有关联 摄像头
//DeviceModel*deviceModel=[_deviceArr objectAtIndex:indexpath.row];
//要删除的设设备id
// //存在则 解除关系 删除对应的cameraId
// NSMutableArray *guanxiiArr= [[DataCenter defaultDtacenter] valueForKey:@"devicamerArr"];
//
// for (DeviceCameraModel *model in guanxiiArr) {
//
// if (self.currentDevice.deviceId == model.deviceId ) {
//
//
// [guanxiiArr removeObject:model];
// //保存新关系数组
// [[DataCenter defaultDtacenter] setValue:guanxiiArr forKey:@"devicamerArr"];
//
// }
//
// }
[self deleteDeviceRequset];
}]];
}
-(void)deleteDeviceRequset{
AFHTTPRequestOperationManager*mannager=[AFHTTPRequestOperationManager manager];
AFSecurityPolicy*policy = [[AFSecurityPolicy alloc]init];
policy.validatesDomainName=NO;
policy.validatesCertificateChain=NO;
mannager.securityPolicy =policy;
mannager.responseSerializer=[AFHTTPResponseSerializer serializer];
NSMutableDictionary * para = [NSMutableDictionary dictionary];
NSString *priId=self.devicemodel.deviceId;
;
NSString*userId=self.devicemodel.userId;
[para setValue:priId forKey:@"priId.deviceId"];
[para setValue:userId forKey:@"priId.userId"];
// __weak typeof (self)weakSelf=self;
[mannager POST:kDeleteDeviceUser parameters:para success:^(AFHTTPRequestOperation *operation, id responseObject) {
if (responseObject) {
NSDictionary*resultDic=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
NSLog(@"result:%@",resultDic[@"result"]);
if ([resultDic[@"result"] isEqualToString:@"100"]) {
[self deleteDeviceRequsetSus];
}else if ([resultDic[@"result"] isEqualToString:@"101"]){
// [self showTitle:@"" messsage:@"删除失败"];
[self showLableAction:@"删除失败"];
}else if ([resultDic[@"result"] isEqualToString:@"301"]){
// [self showTitle:@"" messsage:@"请求验证失败,请重新登陆"];
[self showLableAction:@"请求验证失败,请重新登陆"];
}else if ([resultDic[@"result"] isEqualToString:@"302"]){
// [self showTitle:@"" messsage:@"请求被舍弃,未执行"];
[self showLableAction:@"请求被舍弃,未执行"];
}
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
// [self showTitle:@"" messsage:@"请求异常"];
[self showLableAction:@"请求异常"];
}];
}
-(void)deleteDeviceRequsetSus{
}
#pragma mark - 分享设备
-(void)fenXiangSheBei{
CreatErWeiMaController*vc=[[CreatErWeiMaController alloc]init]
;
vc.erdevicemodel=self.devicemodel;
[self.navigationController pushViewController:vc animated:YES];
}
#pragma mark 刷新
-(void)wenduRequest{
}
-(void)creatRefreshView{
__weak typeof (self)weakSelf=self;
[weakSelf.tableView addRefreshHeaderViewWithAniViewClass:[JHRefreshAmazingAniView class] beginRefresh:^{
if (weakSelf.isRefeshing) {
return ;
}
weakSelf.isRefeshing=YES;
if (_isconnect==YES) {
//
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf wenduRequest];
});
}else{// socket中断
[weakSelf InitSocket];
}
}];
}
-(void)endRefreshing{
if (self.isRefeshing) {
self.isRefeshing=NO;
[self.tableView headerEndRefreshingWithResult:JHRefreshResultSuccess];
}
}
@end