新版本

This commit is contained in:
roy
2019-03-12 09:26:46 +08:00
parent cbbfcb098a
commit c08d198e11
431 changed files with 19432 additions and 9136 deletions
+379
View File
@@ -0,0 +1,379 @@
//
// IfishBaseVc.m
// Ifish
//
// Created by 罗艺 on 2018/9/23.
// Copyright © 2018年 lianlian. All rights reserved.
//
#import "IfishBaseVc.h"
#import "LXPopView.h"
#import "DXPopover.h"
#import "CreatErWeiMaController.h"
#import "JHRefreshAmazingAniView.h"
#import "UIScrollView+JHRefresh.h"
@interface IfishBaseVc ()<IfishCommuniteDelegate,LxPopViewDelegate>
@property(nonatomic,strong)DXPopover *popover;
@end
@implementation IfishBaseVc
- (void)viewDidLoad {
[super viewDidLoad];
[self InitSocket];
[Socketsingleton sharedInstance].communiteDelegate=self;
// Do any additional setup after loading the view.
}
- (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];
}
}
-(void)presentPopView{
UIImage *image = [UIImage imageNamed:@"popover_background_image_notrangle"];
NSArray *titleImgs = nil;
NSArray *titles=nil;
LXPopView *pop=[[LXPopView alloc] init];
CGFloat popRowH=160*(image.size.height/image.size.width);
if ([self.devicemodel.isMaster isEqualToString:@"1"]) {
//主控
pop.frame = CGRectMake(0, 0, 160, 160*(image.size.height/image.size.width) + (popRowH -12)/2);
titleImgs = @[@"ifishdropview_edite_device",@"ifishdropview_delect_device",@"Ifish_share_device"];
titles=@[@"修改名称",@"删除设备",@"分享设备"];
}else{
pop.frame = CGRectMake(0,0, 160, 160*(image.size.height/image.size.width));
titleImgs = @[@"ifishdropview_edite_device",@"ifishdropview_delect_device"];
titles=@[@"修改名称",@"删除设备"];
}
pop.delegate = self;
pop.backgroundImage =image
;
pop.titles = titles;
pop.titleImgs =titleImgs;
DXPopover *popover = [DXPopover popover];
self.popover = popover;
popover.arrowSize = CGSizeMake(0.0,0.0);
[popover showAtView:self.navigationItem.rightBarButtonItem.customView withContentView:pop];
NSLog(@"设备右侧pop");
}
#pragma mark - PopViewDelagate
-(void)disSelectedPopViewIndex:(NSIndexPath *)Index{
[self.popover dismiss];
if (Index.row == 0) {
//修改名称
[self shezhiMingCheng];
}else if (Index.row == 1){
//删除设备
[self deletDevice];
}else if (Index.row == 2){
//分享设备
[self fenXiangSheBei];
}
}
#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];
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