//
|
// EZSDK.m
|
// EZSDK
|
//
|
// Created by 陈嘉乐 on 2021/1/27.
|
//
|
|
#import "EZSDK.h"
|
//#import "DeviceInfo.h"
|
#import "EZDeviceInfo.h"
|
#import "EZOpenSDK.h"
|
#import "GlobalKit.h"
|
#import "EZAccessToken.h"
|
#import "NSArray+DDKit.h"
|
#import "EZAddByQRCodeViewController.h"
|
#import "EZLivePlayViewController.h"
|
#import "EZSettingViewController.h"
|
#import "EZPlaybackViewController.h"
|
#import "EZDeviceTableViewController.h"
|
#import "EZHCNetDeviceSDK.h"
|
#import "EZMessagePhotoViewController.h"
|
#import "HDLEZVisitorRecordViewController.h"
|
#import "HDLEZDeviceMsgListViewController.h"
|
|
@implementation EZSDK
|
|
///
|
+ (instancetype)sharedInstance{
|
static EZSDK *instance = nil;
|
static dispatch_once_t onceToken;
|
dispatch_once(&onceToken, ^{
|
if (!instance) {
|
instance = [[EZSDK alloc] init];
|
}
|
});
|
return instance;
|
}
|
|
static BOOL isHavelibInit=NO;
|
|
/**
|
初始化SDK
|
传入国内版key 和海外版globalAppKey
|
*/
|
- (BOOL)initLibWithAppKey:(NSString *)appKey globalAppKey:(NSString *)globalAppKey
|
{
|
if (!isHavelibInit) {
|
[EZOPENSDK setDebugLogEnable:YES];
|
// isHavelibInit=YES;
|
// NSLog(@"第一次初始化萤石库");
|
if (!LanguageIsChinese) {
|
//海外版
|
isHavelibInit = [EZGlobalSDK initLibWithAppKey:globalAppKey];
|
NSLog(@"海外版key--%@",globalAppKey);
|
}else{
|
isHavelibInit = [EZOpenSDK initLibWithAppKey:appKey];
|
[[GlobalKit shareKit] setHdlAppKey:appKey];
|
NSLog(@"国内版key--%@", appKey);
|
}
|
[EZHCNetDeviceSDK initSDK];
|
[EZOPENSDK enableP2P:YES];
|
// [EZOPENSDK setDebugLogEnable:YES];
|
NSLog(@"EZOpenSDK Version = %@", [EZOPENSDK getVersion]);
|
// NSLog(@"EZOpenSDK treamToken= %@", );
|
|
}
|
return isHavelibInit;
|
}
|
|
/**
|
设置SDK的accessToken
|
*/
|
-(void)setEZAccessToken:(NSString *) accessToken
|
{
|
[[GlobalKit shareKit] setAccessToken:accessToken];
|
[EZOPENSDK setAccessToken:accessToken];
|
}
|
|
/**
|
设置HDLSDK的accessToken
|
*/
|
-(void)setHDlAccessToken:(NSString *) accessToken refreshToken:(NSString *) refreshToken
|
{
|
[[GlobalKit shareKit] setHdlAccessToken:accessToken];
|
[[GlobalKit shareKit] setHdlRefreshToken:refreshToken];
|
}
|
/**
|
设置SDK的河东接口的requestHttpsHost和平台 标识,1.on+(默认) 2.evoyo
|
*/
|
-(void)setRequestHttpsHostAndPlatform:(NSString *) requestHttpsHost platform:(int)platform homeId:(NSString *)homeId{
|
[[GlobalKit shareKit] setGlobalRequestHttpsHost:requestHttpsHost];
|
[[GlobalKit shareKit] setHdlPlatform:platform];
|
[[GlobalKit shareKit] setHdlHomeId:homeId];
|
}
|
|
//获取当前屏幕显示的viewcontroller (这里面获取的相当于rootViewController)
|
-(UINavigationController *)getCurrentVC
|
{
|
UIWindow * window = [[UIApplication sharedApplication] keyWindow];
|
if (window.windowLevel != UIWindowLevelNormal)
|
{
|
NSArray *windows = [[UIApplication sharedApplication] windows];
|
for(UIWindow * tmpWin in windows)
|
{
|
if (tmpWin.windowLevel == UIWindowLevelNormal)
|
{
|
window = tmpWin;
|
break;
|
}
|
}
|
}
|
|
return (UINavigationController *)window.rootViewController;
|
}
|
|
|
/**
|
直接跳转到萤石摄像头列表
|
*/
|
-(void)go2EZvizMonitor
|
{
|
// [GlobalKit shareKit].deviceType=HDLEZDeviceType_Default;
|
// // NSLog(@"go2EZvizMonitor");
|
// //获取EZMain的stroyboard文件
|
// UIStoryboard *ezMainStoryboard = [UIStoryboard storyboardWithName:@"EZMain" bundle:nil];
|
// //获取EZMain.storyboard的实例ViewController--获取摄像头列表
|
// EZDeviceTableViewController *instanceVC = [ezMainStoryboard instantiateViewControllerWithIdentifier:@"EZCameraList"];
|
// //push摄像头列表的viewController
|
// [[self getCurrentVC] setNavigationBarHidden:NO];
|
// // NSLog(@"willpush********");
|
// [[self getCurrentVC] pushViewController:instanceVC animated:YES];
|
// // NSLog(@"had pushed********");
|
[self toEZDeviceListViewWithFilterTypes:@[@""]];
|
}
|
|
/**
|
直接跳转到萤石摄像头列表(筛掉门锁设备)
|
@param filterTepes 过滤型号数组
|
*/
|
- (void)toEZDeviceListViewWithFilterTypes:(NSArray*)filterTepes{
|
[GlobalKit shareKit].deviceType=HDLEZDeviceType_Default;
|
//获取EZMain的stroyboard文件
|
UIStoryboard *ezMainStoryboard = [UIStoryboard storyboardWithName:@"EZMain" bundle:nil];
|
//获取EZMain.storyboard的实例ViewController--获取摄像头列表
|
EZDeviceTableViewController *instanceVC = [ezMainStoryboard instantiateViewControllerWithIdentifier:@"EZCameraList"];
|
instanceVC.filterTypes=filterTepes;
|
//push摄像头列表的viewController
|
[[self getCurrentVC] setNavigationBarHidden:NO];
|
[[self getCurrentVC] pushViewController:instanceVC animated:YES];
|
}
|
|
/**
|
跳转添加添加设备
|
*/
|
-(void)addEzvizMonitor
|
{
|
// // NSLog(@"添加摄像头");
|
// if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
|
// UIStoryboard *addDeviceStoryBoard = [UIStoryboard storyboardWithName:@"AddDevice" bundle:nil];
|
// EZAddByQRCodeViewController *rootViewController = [addDeviceStoryBoard instantiateViewControllerWithIdentifier:@"AddByQRCode"];
|
// [[self getCurrentVC] setNavigationBarHidden:NO];
|
// [[self getCurrentVC] pushViewController:rootViewController animated:YES];
|
// } else {
|
// // [UIView dd_showMessage:@"iOS 7.0以下扫码功能请自行实现"];
|
// NSLog(@"iOS 7.0以下扫码功能请自行实现");
|
// }
|
[self addEzvizMonitorWithDeviceType:@""];
|
}
|
|
/**
|
跳转添加添加设备
|
@param deviceType 设备类型
|
*/
|
- (void)addEzvizMonitorWithDeviceType:(NSString *)deviceType{
|
HDLEZDeviceType type=[deviceType isEqualToString:HDLEZ_DOOR_SPK] ? HDLEZDeviceType_Door : HDLEZDeviceType_Default;
|
// NSLog(@"添加摄像头");
|
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
|
UIStoryboard *addDeviceStoryBoard = [UIStoryboard storyboardWithName:@"AddDevice" bundle:nil];
|
EZAddByQRCodeViewController *rootViewController = [addDeviceStoryBoard instantiateViewControllerWithIdentifier:@"AddByQRCode"];
|
rootViewController.deviceType=type;
|
[[self getCurrentVC] setNavigationBarHidden:NO];
|
[[self getCurrentVC] pushViewController:rootViewController animated:YES];
|
} else {
|
// [UIView dd_showMessage:@"iOS 7.0以下扫码功能请自行实现"];
|
NSLog(@"iOS 7.0以下扫码功能请自行实现");
|
}
|
}
|
|
/**
|
查看视频监控直播
|
*/
|
-(void)Play:(EZDeviceInfo*)deviceInfo
|
{
|
[GlobalKit shareKit].deviceType=HDLEZDeviceType_Default;
|
UIStoryboard *addDeviceStoryBoard = [UIStoryboard storyboardWithName:@"EZMain" bundle:nil];
|
EZLivePlayViewController *rootViewController = [addDeviceStoryBoard instantiateViewControllerWithIdentifier:@"EZLivePlayViewController"];
|
// NSLog(@"play--iphone--rootViewController");
|
rootViewController.deviceInfo=(EZDeviceInfo *)deviceInfo;
|
NSLog(@"play--iphone--deviceName -%@",rootViewController.deviceInfo.deviceName);
|
// rootViewController.cameraIndex=0;
|
[[self getCurrentVC] setNavigationBarHidden:NO];
|
[[self getCurrentVC] pushViewController:rootViewController animated:YES];
|
|
|
}
|
|
/// 指定序列号播放
|
/// @param deviceSerial 序列号
|
-(void)PlayWithDeviceSerial:(NSString *)deviceSerial{
|
//获取设备列表接口
|
[EZOpenSDK getDeviceInfo:deviceSerial completion:^(EZDeviceInfo *deviceInfo, NSError *error) {
|
if(error)
|
{
|
NSLog(@"EZ 查询设备信息失败");
|
return;
|
}
|
if (deviceInfo) {
|
[self Play:deviceInfo];
|
}
|
}];
|
}
|
|
/**
|
根据序列号进入门锁视频
|
@param deviceSerial 序列号
|
@param deviceId 设备id
|
@param deviceType 设备spk(用于区分是否为门锁)
|
*/
|
-(void)PlayWithDeviceSerial:(NSString *)deviceSerial deviceId:(NSString*)deviceId deviceType:(NSString *)deviceType{
|
[GlobalKit shareKit].deviceType=[deviceType isEqualToString:HDLEZ_DOOR_SPK] ? HDLEZDeviceType_Door : HDLEZDeviceType_Default;
|
UIStoryboard *ezMainStoryBoard = [UIStoryboard storyboardWithName:@"EZMain" bundle:nil];
|
EZLivePlayViewController *vc = [ezMainStoryBoard instantiateViewControllerWithIdentifier:@"EZLivePlayViewController"];
|
vc.deviceId=deviceId;
|
vc.deviceSerial=deviceSerial;
|
[[self getCurrentVC] setNavigationBarHidden:NO];
|
[[self getCurrentVC] pushViewController:vc animated:YES];
|
}
|
|
/**
|
打开摄像头设置页面
|
*/
|
-(void)setting:(EZDeviceInfo*)deviceInfo
|
{
|
UIStoryboard *settingStoryBoard=[UIStoryboard storyboardWithName:@"EZMain" bundle:nil];
|
EZSettingViewController *settingVC=[settingStoryBoard instantiateViewControllerWithIdentifier:@"EZSettingViewController"];
|
settingVC.deviceInfo=(EZDeviceInfo *)deviceInfo;
|
[[self getCurrentVC] setNavigationBarHidden:NO];
|
[[self getCurrentVC] pushViewController:settingVC animated:YES];
|
}
|
|
/**
|
回放播放历史
|
*/
|
-(void)playBackVideo:(EZDeviceInfo*)deviceInfo
|
{
|
UIStoryboard *playBackStoryBoard=[UIStoryboard storyboardWithName:@"EZMain" bundle:nil];
|
EZPlaybackViewController *playBackVC=[playBackStoryBoard instantiateViewControllerWithIdentifier:@"EZPlaybackViewController"];
|
playBackVC.deviceInfo=(EZDeviceInfo *)deviceInfo;
|
[[self getCurrentVC] setNavigationBarHidden:NO];
|
[[self getCurrentVC] pushViewController:playBackVC animated:YES];
|
}
|
|
/**临时密码页
|
@param deviceId 设备id
|
*/
|
- (void)toTemPassView:(NSString*)deviceId{
|
HDLEZVisitorRecordViewController *vc=[[HDLEZVisitorRecordViewController alloc] init];
|
vc.deviceId=deviceId;
|
[[self getCurrentVC] setNavigationBarHidden:YES];
|
[[self getCurrentVC] pushViewController:vc animated:YES];
|
}
|
|
/**设备历史记录页
|
@param deviceId 设备id
|
*/
|
- (void)toDeviceMsgListView:(NSString*)deviceId{
|
HDLEZDeviceMsgListViewController *vc=[[HDLEZDeviceMsgListViewController alloc] init];
|
vc.deviceId=deviceId;
|
[[self getCurrentVC] setNavigationBarHidden:YES];
|
[[self getCurrentVC] pushViewController:vc animated:YES];
|
|
}
|
|
////
|
//-(void)goToEZMessagePhotoVC:(EZAlarmInfo*)alarmInfo{
|
// UIStoryboard *addDeviceStoryBoard = [UIStoryboard storyboardWithName:@"EZMain" bundle:nil];
|
// EZMessagePhotoViewController *rootViewController = [addDeviceStoryBoard instantiateViewControllerWithIdentifier:@"EZMessagePhotoViewController"];
|
// // NSLog(@"play--iphone--rootViewController");
|
// rootViewController.info = alarmInfo;
|
//// NSLog(@"play--iphone--deviceName -%@",rootViewController.deviceInfo.deviceName);
|
//// rootViewController.cameraIndex=0;
|
// [[self getCurrentVC] setNavigationBarHidden:NO];
|
// [[self getCurrentVC] pushViewController:rootViewController animated:YES];
|
//}
|
//+(void)MonitorPushMessage:(NSString *)MonitorType ID:(NSString *)ID
|
//{
|
// [CommonList login];
|
// [CommonList getlist:0 pageSize:20 listArray:^(NSArray *listArray) {
|
// for ( NSObject *info in listArray) {
|
// DeviceInfo *ezInfo=(DeviceInfo *)info;
|
// if ([ID isEqualToString:ezInfo.DeviceSerial]) {
|
// NSLog(@"相同id");
|
// [CommonList Play:ezInfo.RealObject];
|
// }
|
// }
|
// }];
|
//}
|
|
//+(void)getlist:(int)pageIndex pageSize:(int)pageSize listArray:(void(^)(NSArray *))listArray
|
//{
|
//
|
// static NSMutableArray *deviceListaArray;
|
// deviceListaArray=nil;
|
// if ([GlobalKit shareKit].accessToken)
|
// {
|
// [EZOPENSDK setAccessToken:[GlobalKit shareKit].accessToken];
|
// //获取列表
|
// [EZOpenSDK getDeviceList:0 pageSize:20 completion:^(NSArray *deviceList, NSInteger totalCount, NSError *error) {
|
// deviceListaArray=[NSMutableArray array];
|
// for (int i=0; i<deviceList.count; i++) {
|
// DeviceInfo *deviceInfos=[[DeviceInfo alloc]init];
|
// EZDeviceInfo *ezDeviceInfo=[deviceList dd_objectAtIndex:i];
|
// deviceInfos.DeviceName=ezDeviceInfo.deviceName;
|
// deviceInfos.DeviceSerial=ezDeviceInfo.deviceSerial;
|
// deviceInfos.DeviceNum=(int)ezDeviceInfo.cameraNum;
|
// deviceInfos.DeviceCameraInfoListSize=1;
|
// deviceInfos.cameraInfo=ezDeviceInfo.cameraInfo;
|
// deviceInfos.RealObject=ezDeviceInfo;
|
// [deviceListaArray addObject:deviceInfos];
|
// }
|
// //block回调
|
// listArray(deviceListaArray);
|
// }];
|
// }
|
//
|
//}
|
|
//+(void)CameraList
|
//{
|
// NSLog(@"收到完成通知回调");
|
// [CommonList go2EZvizMonitor];
|
//}
|
|
//+(NSMutableArray<MonitorData *> *)getMonitorDatas
|
//{
|
// static NSMutableArray<MonitorData *> *monitorDataMutableArr;
|
// if (monitorDataMutableArr==nil) {
|
// monitorDataMutableArr=[[NSMutableArray alloc]init];
|
// }
|
// return monitorDataMutableArr;
|
//}
|
//
|
//+(ICommon*)EZICommon{
|
// static ICommon *ICommons;
|
// if(ICommons==nil)
|
// {
|
// ICommons= [[ICommon alloc]init];
|
//
|
// }
|
// return ICommons;
|
//}
|
|
|
//+(NSArray *)getDeviceList:(int)pageIndex :(int)pageSize
|
//{
|
// static NSMutableArray *deviceListaArray;
|
// deviceListaArray=nil;
|
// //判断本地保存的accessToken,然后向SDK设置AccessToken。
|
// if ([GlobalKit shareKit].accessToken)
|
// {
|
// [EZOPENSDK setAccessToken:[GlobalKit shareKit].accessToken];
|
// //获取列表
|
// [EZOpenSDK getDeviceList:0 pageSize:20 completion:^(NSArray *deviceList, NSInteger totalCount, NSError *error) {
|
// deviceListaArray=[NSMutableArray array];
|
// //怎么将 这里block得到的数据return回去
|
// NSLog(@"原生deviceList.count****%ld",(unsigned long)deviceList.count);
|
// for (int i=0; i<deviceList.count; i++) {
|
// DeviceInfo *deviceInfos=[[DeviceInfo alloc]init];
|
// EZDeviceInfo *ezDeviceInfo=[deviceList dd_objectAtIndex:i];
|
// deviceInfos.DeviceName=ezDeviceInfo.deviceName;
|
// deviceInfos.DeviceSerial=ezDeviceInfo.deviceSerial;
|
// deviceInfos.DeviceNum=(int)ezDeviceInfo.cameraNum;
|
// deviceInfos.DeviceCameraInfoListSize=1;
|
// deviceInfos.cameraInfo=ezDeviceInfo.cameraInfo;
|
// deviceInfos.RealObject=ezDeviceInfo;
|
// [deviceListaArray addObject:deviceInfos];
|
// }
|
// }];
|
// }
|
// else
|
// {
|
// return deviceListaArray=[NSMutableArray array];
|
// }
|
// while (deviceListaArray==nil) {
|
// [NSThread sleepForTimeInterval:1];
|
// }
|
// return deviceListaArray ;
|
//}
|
|
//+(void)login
|
//{
|
// if ([GlobalKit shareKit].accessToken)
|
// {
|
// [EZOPENSDK setAccessToken:[GlobalKit shareKit].accessToken];
|
// NSLog(@"login---1");
|
// }
|
// else
|
// {
|
// [EZOPENSDK openLoginPage:^(EZAccessToken *accessToken) {
|
// [[GlobalKit shareKit] setAccessToken:accessToken.accessToken];
|
// [EZOPENSDK setAccessToken:accessToken.accessToken];
|
// NSLog(@"login---2");
|
// }];
|
// }
|
//}
|
|
|
|
@end
|