417 lines
18 KiB
Objective-C
417 lines
18 KiB
Objective-C
//
|
|
// IfishDataUnity.m
|
|
// Ifish
|
|
//
|
|
// Created by imac on 16/5/26.
|
|
// Copyright © 2016年 imac. All rights reserved.
|
|
//
|
|
|
|
#import "IfishDataUnity.h"
|
|
//#import "JPUSHService.h"
|
|
#import "IfishCameraModel.h"
|
|
#import "IfishNewsModel.h"
|
|
#import "IfishHotBarVc.h"
|
|
#import "Xuanduo2fController.h"
|
|
#import "IfishP2PMonitorController.h"
|
|
|
|
@implementation IfishDataUnity
|
|
|
|
+(IfishDataUnity*)shareDataInstance
|
|
{
|
|
static IfishDataUnity*instance=nil;
|
|
static dispatch_once_t predicate;
|
|
dispatch_once(&predicate, ^{
|
|
instance=[[[self class]alloc]init];
|
|
|
|
|
|
});
|
|
return instance;
|
|
}
|
|
|
|
|
|
#pragma mark -二维码添加
|
|
|
|
-(void)addDeviceByQRCodeWithDic:(NSDictionary *)resultDic addWith:(NSMutableArray *)deviceArry dismiss:(ScanViewController*) scanVC{
|
|
|
|
|
|
// 保存设备信息 单个设备 更改 dic
|
|
|
|
NSDictionary*dataDic=resultDic[@"data"];
|
|
|
|
[self saveDeviceDataWith:deviceArry Withdic:dataDic dissmissScanVC:(ScanViewController *)scanVC];
|
|
|
|
}
|
|
|
|
|
|
//保存 单个设备信息
|
|
|
|
-(void)saveDeviceDataWith:(NSMutableArray *)deviceArry Withdic:(NSDictionary *)dataDic dissmissScanVC:(ScanViewController *)scanVC
|
|
{
|
|
|
|
|
|
if (dataDic[@"cameraId"])
|
|
{
|
|
IfishCameraModel *camera=[[IfishCameraModel alloc] initWithDict:dataDic];
|
|
[deviceArry insertObject:camera atIndex:0];
|
|
[[DataCenter defaultDtacenter]setValue:deviceArry forKey:@"cameraArr"];
|
|
if (scanVC)
|
|
{
|
|
[scanVC dismissViewControllerAnimated:YES completion:^{
|
|
IfishP2PMonitorController *p2pVC=[[IfishP2PMonitorController alloc] init];
|
|
p2pVC.contact = camera;
|
|
UINavigationController *nav=[[UINavigationController alloc] initWithRootViewController:p2pVC];
|
|
UIApplication*app=[UIApplication sharedApplication];
|
|
AppDelegate*app1=(AppDelegate*)app.delegate;
|
|
app1.window.rootViewController=nav;
|
|
}];
|
|
}
|
|
else
|
|
{
|
|
IfishP2PMonitorController *p2pVC=[[IfishP2PMonitorController alloc] init];
|
|
p2pVC.contact = camera;
|
|
UINavigationController *nav=[[UINavigationController alloc] initWithRootViewController:p2pVC];
|
|
UIApplication*app=[UIApplication sharedApplication];
|
|
AppDelegate*app1=(AppDelegate*)app.delegate;
|
|
app1.window.rootViewController=nav;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
DeviceModel*devicemodel=[[DeviceModel alloc]initWithDict:dataDic];
|
|
//设备
|
|
[deviceArry insertObject:devicemodel atIndex:0];
|
|
|
|
[[DataCenter defaultDtacenter]setValue:deviceArry forKey:@"deviceInfo"];
|
|
|
|
if ([devicemodel.type isEqualToString:DECICE_TYPE_XUANDUO3F]) {
|
|
NSMutableDictionary*petStores=[[DataCenter defaultDtacenter] valueForKey:@"petStores"];
|
|
for (NSMutableArray*array in petStores.allValues) {
|
|
|
|
|
|
[array insertObject:devicemodel atIndex:0];
|
|
break;
|
|
}
|
|
|
|
[[DataCenter defaultDtacenter]setValue:petStores forKey:@"petStores"];
|
|
[[DataCenter defaultDtacenter].cache setString:devicemodel.macAddress forKey:@"currentPetDevice"];
|
|
|
|
}
|
|
|
|
[self initAppCenterVcWith:devicemodel addWithdissMisVc:scanVC];
|
|
}
|
|
|
|
|
|
}
|
|
|
|
#pragma mark -设置根视图
|
|
|
|
-(void)initAppCenterVcWith:(DeviceModel*)devicemodel addWithdissMisVc:(ScanViewController *)scanVC{
|
|
|
|
if (scanVC) {
|
|
|
|
// [[UIApplication sharedApplication].delegate.window.rootViewController.view makeToastActivityBlackBack];
|
|
|
|
[scanVC dismissViewControllerAnimated:YES completion:^{
|
|
|
|
|
|
// [[UIApplication sharedApplication].delegate.window.rootViewController.view hideToastActivity];
|
|
|
|
[self setrootWith:devicemodel];
|
|
}];
|
|
|
|
return;
|
|
}
|
|
|
|
|
|
[self setrootWith:devicemodel];
|
|
|
|
}
|
|
|
|
-(void)setrootWith:(DeviceModel*)devicemodel{
|
|
|
|
// NSString *tost=[NSString stringWithFormat:@"type%@",devicemodel.type];
|
|
// [[UIApplication sharedApplication].keyWindow makeToast:tost];
|
|
// 先判断是否授权
|
|
if ([devicemodel.type isEqual:[NSNull null]]||!devicemodel.type) {
|
|
//未知类型 跳转未授权 显示未知类型
|
|
devicemodel.isBlacklist = @"1";
|
|
}
|
|
|
|
if ([devicemodel.isBlacklist isEqual:[NSNull null]]) {
|
|
devicemodel.isBlacklist = @"1";
|
|
}
|
|
|
|
if ([devicemodel.isBlacklist isEqualToString:@"1"]) {
|
|
//黑名单 未授权 跳转到 未授权界面
|
|
[self setBlackViewWithDevice:devicemodel];
|
|
|
|
}else{
|
|
|
|
if ([devicemodel.controlAmount isEqual:[NSNull null]]) {
|
|
// 服务器返回此字段 为NSUll 时默认到0控
|
|
devicemodel.controlAmount = 0;
|
|
}
|
|
|
|
//v3.5后新加硬件类型字段 判断硬件类型
|
|
//新增硬件类型 原来的设备用 controlAmount 和timerAmount 判断 新加设备按类型区分
|
|
//硬件型号: 1c 三控(温控),硬件型号:cc 四川聚能 松诺新bd 睿芯独立2a
|
|
if ([devicemodel.type isEqualToString:DECICE_TYPE_THREETMP]) {
|
|
RuSunHaveHeateViewController *ruSuncenter=[[RuSunHaveHeateViewController alloc] init];
|
|
ruSuncenter.currentDevice = devicemodel;
|
|
UIApplication*app=[UIApplication sharedApplication];
|
|
AppDelegate*app1=(AppDelegate*)app.delegate;
|
|
UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:ruSuncenter];
|
|
[nav setNavbgImage:[UIImage imageNamed:@"blackbar.png"]];
|
|
app1.window.rootViewController=nav;
|
|
|
|
}else if ([devicemodel.type isEqualToString:DECICE_TYPE_JUNENGCC]){
|
|
|
|
[self setBlackViewWithDevice:devicemodel];
|
|
|
|
}else if ([devicemodel.type isEqualToString:DECICE_TYPE_SONGNEWBD]){
|
|
|
|
SongNuoDBCenterViewController *SongNuoBDcenter=[[SongNuoDBCenterViewController alloc] init];
|
|
SongNuoBDcenter.currentDevice = devicemodel;
|
|
UIApplication*app=[UIApplication sharedApplication];
|
|
AppDelegate*app1=(AppDelegate*)app.delegate;
|
|
UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:SongNuoBDcenter];
|
|
[nav setNavbgImage:[UIImage imageNamed:@"blackbar.png"]];
|
|
app1.window.rootViewController=nav;
|
|
|
|
}else if ([devicemodel.type isEqualToString:DECICE_TYPE_RUSUN2A]){
|
|
|
|
RunSun84biteCenterViewController *RunSun84center=[[RunSun84biteCenterViewController alloc] init];
|
|
RunSun84center.currentDevice = devicemodel;
|
|
UIApplication*app=[UIApplication sharedApplication];
|
|
AppDelegate*app1=(AppDelegate*)app.delegate;
|
|
UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:RunSun84center];
|
|
[nav setNavbgImage:[UIImage imageNamed:@"blackbar.png"]];
|
|
app1.window.rootViewController=nav;
|
|
|
|
} else if ([devicemodel.type isEqualToString:DECICE_TYPE_RUIMEI]) {
|
|
RuiMeiViewController *ruimeiCenter=[[RuiMeiViewController alloc] init];
|
|
ruimeiCenter.currentDevice = devicemodel;
|
|
UIApplication*app=[UIApplication sharedApplication];
|
|
AppDelegate*app1=(AppDelegate*)app.delegate;
|
|
UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:ruimeiCenter];
|
|
[nav setNavbgImage:[UIImage imageNamed:@"blackbar.png"]];
|
|
app1.window.rootViewController=nav;
|
|
|
|
}else if ([devicemodel.type isEqualToString:DECICE_TYPE_hotBar]) {
|
|
|
|
IfishHotBarVc*barVc=InitObject(IfishHotBarVc);
|
|
barVc.devicemodel = devicemodel;
|
|
barVc.hidesBottomBarWhenPushed=YES;
|
|
|
|
UIApplication*app=[UIApplication sharedApplication];
|
|
AppDelegate*app1=(AppDelegate*)app.delegate;
|
|
UITabBarController*tabVc= (UITabBarController*)app1.window.rootViewController;
|
|
tabVc.selectedIndex=0;
|
|
UINavigationController*navVc=(UINavigationController*)tabVc.childViewControllers[tabVc.selectedIndex];
|
|
[navVc pushViewController:barVc animated:YES];
|
|
}else if([devicemodel.type isEqualToString:DECICE_TYPE_XUANDUO2F]){
|
|
//绚多新设备
|
|
Xuanduo2fController *xuanduo2fVc = [Xuanduo2fController new];
|
|
xuanduo2fVc.currentDevice = devicemodel;
|
|
UINavigationController *xuanduo2fNav=[[UINavigationController alloc]initWithRootViewController:xuanduo2fVc];
|
|
[UIApplication sharedApplication].delegate.window.rootViewController = xuanduo2fNav;
|
|
}
|
|
else if([devicemodel.type isEqualToString:DECICE_TYPE_XUANDUO3F]||[devicemodel.type isEqualToString:DECICE_TYPE_XUANDUO4F]||[devicemodel.type isEqualToString:DECICE_TYPE_XUANDUO5F]){
|
|
//绚多新设备
|
|
Xuanduo2fController *xuanduo2fVc = [Xuanduo2fController new];
|
|
xuanduo2fVc.currentDevice = devicemodel;
|
|
UINavigationController *xuanduo2fNav=[[UINavigationController alloc]initWithRootViewController:xuanduo2fVc];
|
|
[UIApplication sharedApplication].delegate.window.rootViewController = xuanduo2fNav;
|
|
}
|
|
|
|
else{
|
|
|
|
int controlAmount=[devicemodel.controlAmount intValue];
|
|
|
|
switch (controlAmount) {
|
|
|
|
case IFISH_DEVICE_CONTROLAMOUNT0:
|
|
|
|
{
|
|
//零控
|
|
NoneControlCenterViewController *none=[[NoneControlCenterViewController alloc] init];
|
|
none.currentDevice = devicemodel;
|
|
|
|
UIApplication*app=[UIApplication sharedApplication];
|
|
AppDelegate*app1=(AppDelegate*)app.delegate;
|
|
UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:none];
|
|
[nav setNavbgImage:[UIImage imageNamed:@"blackbar.png"]];
|
|
app1.window.rootViewController=nav;
|
|
|
|
}
|
|
break;
|
|
|
|
case IFISH_DEVICE_CONTROLAMOUNT2:
|
|
|
|
{
|
|
// 两控
|
|
|
|
TwoControlCenterController *twocontrolCenter=[[TwoControlCenterController alloc] init];
|
|
twocontrolCenter.currentDevice = devicemodel;
|
|
|
|
UIApplication*app=[UIApplication sharedApplication];
|
|
AppDelegate*app1=(AppDelegate*)app.delegate;
|
|
UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:twocontrolCenter];
|
|
[nav setNavbgImage:[UIImage imageNamed:@"blackbar.png"]];
|
|
app1.window.rootViewController=nav;
|
|
|
|
|
|
|
|
}
|
|
break;
|
|
|
|
case IFISH_DEVICE_CONTROLAMOUNT3:
|
|
|
|
{
|
|
// 三控YooseeCenterViewController
|
|
ThreeControlCenterViewController *threeControlCenter=[[ThreeControlCenterViewController alloc] init];
|
|
threeControlCenter.currentDevice = devicemodel;
|
|
|
|
//ICSDrawerController*ics=[[ICSDrawerController alloc]initWithLeftViewController:left centerViewController:threeControlCenter rightViewController:rightVC];
|
|
|
|
UIApplication*app=[UIApplication sharedApplication];
|
|
AppDelegate*app1=(AppDelegate*)app.delegate;
|
|
UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:threeControlCenter];
|
|
[nav setNavbgImage:[UIImage imageNamed:@"blackbar.png"]];
|
|
app1.window.rootViewController=nav;
|
|
|
|
|
|
|
|
}
|
|
break;
|
|
|
|
case IFISH_DEVICE_CONTROLAMOUNT4:
|
|
|
|
{
|
|
|
|
|
|
int timerAmount =[devicemodel.timerAmount intValue];
|
|
|
|
if (timerAmount == 8) {
|
|
|
|
// 四控 8定时器
|
|
// FourControlViewController *fourControlCenter=[[FourControlViewController alloc] init];
|
|
FourControlNormalCenterController *fourControlCenter=[[FourControlNormalCenterController alloc] init];
|
|
|
|
fourControlCenter.currentDevice = devicemodel;
|
|
|
|
UIApplication*app=[UIApplication sharedApplication];
|
|
AppDelegate*app1=(AppDelegate*)app.delegate;
|
|
UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:fourControlCenter];
|
|
[nav setNavbgImage:[UIImage imageNamed:@"blackbar.png"]];
|
|
app1.window.rootViewController=nav;
|
|
|
|
}else if (timerAmount == 6){
|
|
//可丽爱 4控制 6定时器
|
|
|
|
KeLiAiCenterViewController *keliaicenterVC=[[KeLiAiCenterViewController alloc] init];
|
|
keliaicenterVC.currentDevice = devicemodel;
|
|
|
|
UIApplication*app=[UIApplication sharedApplication];
|
|
AppDelegate*app2=(AppDelegate*)app.delegate;
|
|
UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:keliaicenterVC];
|
|
[nav setNavbgImage:[UIImage imageNamed:@"blackbar.png"]];
|
|
app2.window.rootViewController=nav;
|
|
|
|
|
|
}else{
|
|
NSString *tost=[NSString stringWithFormat:@"未知错误4控%d定时器",timerAmount];
|
|
[[UIApplication sharedApplication].keyWindow makeToast:tost];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IFISH_DEVICE_CONTROLAMOUNT5:
|
|
|
|
{
|
|
// 绚 多
|
|
XuToCenterViewController *XuToCenter=[[XuToCenterViewController alloc] init];
|
|
XuToCenter.currentDevice = devicemodel;
|
|
|
|
|
|
//ICSDrawerController*ics=[[ICSDrawerController alloc]initWithLeftViewController:left centerViewController:XuToCenter rightViewController:rightVC];
|
|
UIApplication*app=[UIApplication sharedApplication];
|
|
AppDelegate*app1=(AppDelegate*)app.delegate;
|
|
UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:XuToCenter];
|
|
[nav setNavbgImage:[UIImage imageNamed:@"blackbar.png"]];
|
|
app1.window.rootViewController=nav;
|
|
}
|
|
|
|
break;
|
|
|
|
case IFISH_DEVICE_CONTROLAMOUNT8 :
|
|
|
|
{
|
|
//松诺
|
|
SonNuoCenterViewController *songNu=[[SonNuoCenterViewController alloc] init];
|
|
|
|
//ICSDrawerController*ics=[[ICSDrawerController alloc]initWithLeftViewController:left centerViewController:songNu rightViewController:rightVC];
|
|
|
|
songNu.currentDevice = devicemodel;
|
|
UIApplication*app=[UIApplication sharedApplication];
|
|
AppDelegate*app1=(AppDelegate*)app.delegate;
|
|
UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:songNu];
|
|
[nav setNavbgImage:[UIImage imageNamed:@"blackbar.png"]];
|
|
app1.window.rootViewController=nav;
|
|
|
|
}
|
|
|
|
|
|
default:
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
-(void)setBlackViewWithDevice:(DeviceModel *)devicemodel
|
|
{
|
|
IfishBlackListCenterViewController *blackVC=[[IfishBlackListCenterViewController alloc] init];
|
|
blackVC.currentDevice = devicemodel;
|
|
|
|
if ([devicemodel.type isEqual:[NSNull null]]||!devicemodel.type) {
|
|
//未知类型 跳转未授权 显示位置类型
|
|
blackVC.stateText = @"未知类型";
|
|
|
|
}else{
|
|
|
|
if ([devicemodel.type isEqualToString:DECICE_TYPE_JUNENGCC]) {
|
|
blackVC.stateText = @"未知类型";
|
|
}
|
|
|
|
if ([devicemodel.type isEqualToString:DECICE_TYPE_SONGNEWBD]) {
|
|
blackVC.stateText = @"未知类型";
|
|
}
|
|
|
|
}
|
|
|
|
UIApplication*app=[UIApplication sharedApplication];
|
|
AppDelegate*app1=(AppDelegate*)app.delegate;
|
|
UINavigationController*nav=[[UINavigationController alloc]initWithRootViewController:blackVC];
|
|
[nav setNavbgImage:[UIImage imageNamed:@"blackbar.png"]];
|
|
app1.window.rootViewController=nav;
|
|
|
|
}
|
|
|
|
//设置根视图
|
|
-(void)setAppTabRoot{
|
|
|
|
IfishMianTabViewController *mianVC=[[IfishMianTabViewController alloc] init];
|
|
[UIApplication sharedApplication].delegate.window.rootViewController=mianVC;
|
|
|
|
|
|
}
|
|
|
|
@end
|