Demo/EZOpensdk_iOS_4.15.1_build20201104/Demo/EZOpenSDKDemo.xcodeproj/project.pbxproj
@@ -139,8 +139,11 @@ 49AF550D1F44423B007362EA /* EZLocalCameraListViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 49AF550C1F44423B007362EA /* EZLocalCameraListViewController.m */; }; 49D4B40D1F66A44000ADF471 /* EZDdnsDeviceTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 49D4B40C1F66A44000ADF471 /* EZDdnsDeviceTableViewController.m */; }; 49D4B4AE1F6BB99900ADF471 /* libbz2.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 49D4B4AD1F6BB99900ADF471 /* libbz2.tbd */; }; B91B6E5225EC9DFF00915F73 /* ResponseData.m in Sources */ = {isa = PBXBuildFile; fileRef = B91B6E5125EC9DFF00915F73 /* ResponseData.m */; }; B95004F125B927D0002D3C58 /* com.hri.hpc.mobile.ios.player.metallib in Resources */ = {isa = PBXBuildFile; fileRef = B95004F025B927D0002D3C58 /* com.hri.hpc.mobile.ios.player.metallib */; }; B95004F725B929EF002D3C58 /* Launch Screen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B95004F625B929EF002D3C58 /* Launch Screen.storyboard */; }; B96C125625E8C5EA00B69941 /* EZSDK.m in Sources */ = {isa = PBXBuildFile; fileRef = B96C125525E8C5EA00B69941 /* EZSDK.m */; }; B96C126725E8F64800B69941 /* EZHttpUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = B96C126625E8F64800B69941 /* EZHttpUtil.m */; }; B9EA4E3825C7E7AB000FFDA2 /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = B9EA4E0725C7E7AB000FFDA2 /* LICENSE */; }; B9EA4E3925C7E7AB000FFDA2 /* UIScrollView+MJRefresh.m in Sources */ = {isa = PBXBuildFile; fileRef = B9EA4E0925C7E7AB000FFDA2 /* UIScrollView+MJRefresh.m */; }; B9EA4E3A25C7E7AB000FFDA2 /* MJRefreshConst.m in Sources */ = {isa = PBXBuildFile; fileRef = B9EA4E0A25C7E7AB000FFDA2 /* MJRefreshConst.m */; }; @@ -562,8 +565,14 @@ 49D4B40B1F66A44000ADF471 /* EZDdnsDeviceTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EZDdnsDeviceTableViewController.h; sourceTree = "<group>"; }; 49D4B40C1F66A44000ADF471 /* EZDdnsDeviceTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EZDdnsDeviceTableViewController.m; sourceTree = "<group>"; }; 49D4B4AD1F6BB99900ADF471 /* libbz2.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libbz2.tbd; path = usr/lib/libbz2.tbd; sourceTree = SDKROOT; }; B91B6E5025EC9DFF00915F73 /* ResponseData.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ResponseData.h; sourceTree = "<group>"; }; B91B6E5125EC9DFF00915F73 /* ResponseData.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ResponseData.m; sourceTree = "<group>"; }; B95004F025B927D0002D3C58 /* com.hri.hpc.mobile.ios.player.metallib */ = {isa = PBXFileReference; lastKnownFileType = "archive.metal-library"; path = com.hri.hpc.mobile.ios.player.metallib; sourceTree = "<group>"; }; B95004F625B929EF002D3C58 /* Launch Screen.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = "Launch Screen.storyboard"; sourceTree = "<group>"; }; B96C125425E8C5EA00B69941 /* EZSDK.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EZSDK.h; sourceTree = "<group>"; }; B96C125525E8C5EA00B69941 /* EZSDK.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = EZSDK.m; sourceTree = "<group>"; }; B96C126525E8F64800B69941 /* EZHttpUtil.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = EZHttpUtil.h; sourceTree = "<group>"; }; B96C126625E8F64800B69941 /* EZHttpUtil.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = EZHttpUtil.m; sourceTree = "<group>"; }; B9EA4E0725C7E7AB000FFDA2 /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; }; B9EA4E0925C7E7AB000FFDA2 /* UIScrollView+MJRefresh.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIScrollView+MJRefresh.m"; sourceTree = "<group>"; }; B9EA4E0A25C7E7AB000FFDA2 /* MJRefreshConst.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MJRefreshConst.m; sourceTree = "<group>"; }; @@ -1016,8 +1025,14 @@ 0D8CF4CD1BDF696900A50266 /* Global */ = { isa = PBXGroup; children = ( B96C125425E8C5EA00B69941 /* EZSDK.h */, B96C125525E8C5EA00B69941 /* EZSDK.m */, 0D8CF4CE1BDF696900A50266 /* GlobalKit.h */, 0D8CF4CF1BDF696900A50266 /* GlobalKit.m */, B96C126525E8F64800B69941 /* EZHttpUtil.h */, B96C126625E8F64800B69941 /* EZHttpUtil.m */, B91B6E5025EC9DFF00915F73 /* ResponseData.h */, B91B6E5125EC9DFF00915F73 /* ResponseData.m */, ); path = Global; sourceTree = "<group>"; @@ -1528,7 +1543,7 @@ 0D8CF36B1BDF1ABA00A50266 = { CreatedOnToolsVersion = 7.1; DevelopmentTeam = BVTA78PRYA; ProvisioningStyle = Automatic; ProvisioningStyle = Manual; SystemCapabilities = { com.apple.AccessWiFi = { enabled = 0; @@ -1711,6 +1726,7 @@ 0DCE0C041BE22761000EA68A /* UIButton+DDKit.m in Sources */, C4A41D8223D6E7B200D59722 /* EZVideoTalkViewcontroller.mm in Sources */, 0DCFC11B1BF18DD800EE1FA3 /* HIKLoadPercentView.m in Sources */, B91B6E5225EC9DFF00915F73 /* ResponseData.m in Sources */, 0D2E4BAE1C7DB2E200CA948A /* AFHTTPRequestOperationManager.m in Sources */, 0DCFC11D1BF18DD800EE1FA3 /* HIKLoadViewItem.m in Sources */, 0DCE0BD31BE1C9A9000EA68A /* View+MASAdditions.m in Sources */, @@ -1726,6 +1742,7 @@ 0D90A06B1CABC6A100E78C64 /* EZPlayDemoViewController.m in Sources */, 0DCE0C3C1BE2279F000EA68A /* UIImageView+HighlightedWebCache.m in Sources */, B9EA4E3925C7E7AB000FFDA2 /* UIScrollView+MJRefresh.m in Sources */, B96C125625E8C5EA00B69941 /* EZSDK.m in Sources */, 0D77A3361BE0F38D00B4AD0A /* EZDeviceResultViewController.m in Sources */, 0D5015191BF8B7FF00F13269 /* DALabeledCircularProgressView.m in Sources */, 0D50150C1BF8B77500F13269 /* MWGridViewController.m in Sources */, @@ -1735,6 +1752,7 @@ 0D9ACAEA1C7EE4D100B4DE97 /* UIImageView+AFNetworking.m in Sources */, 0DCE0BD01BE1C9A9000EA68A /* MASViewConstraint.m in Sources */, 0D5015111BF8B77500F13269 /* MWZoomingScrollView.m in Sources */, B96C126725E8F64800B69941 /* EZHttpUtil.m in Sources */, B9EA4E3E25C7E7AB000FFDA2 /* UIView+MJExtension.m in Sources */, 0D50150A1BF8B77500F13269 /* MWCaptionView.m in Sources */, 0D5015101BF8B77500F13269 /* MWTapDetectingView.m in Sources */, @@ -1930,9 +1948,9 @@ CLANG_CXX_LANGUAGE_STANDARD = "compiler-default"; CLANG_CXX_LIBRARY = "libc++"; CODE_SIGN_ENTITLEMENTS = EZOpenSDKDemo/EZOpenSDK.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_IDENTITY = "iPhone Distribution"; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; CODE_SIGN_STYLE = Automatic; CODE_SIGN_STYLE = Manual; CURRENT_PROJECT_VERSION = 200628; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = BVTA78PRYA; @@ -1963,7 +1981,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.hdl.onpro; PRODUCT_NAME = EZOpenSDK; PROVISIONING_PROFILE = ""; PROVISIONING_PROFILE_SPECIFIER = ""; PROVISIONING_PROFILE_SPECIFIER = "ComHdlOnProDevelopment20210225-1"; VALID_ARCHS = "arm64 armv7 armv7s"; WRAPPER_EXTENSION = app; }; Demo/EZOpensdk_iOS_4.15.1_build20201104/Demo/EZOpenSDKDemo/Global/EZHttpUtil.h
New file @@ -0,0 +1,20 @@ // // EZHttpUtil.h // EZOpenSDKDemo // // Created by 陈嘉乐 on 2021/2/26. // Copyright © 2021 hikvision. All rights reserved. // #import <Foundation/Foundation.h> NS_ASSUME_NONNULL_BEGIN @interface EZHttpUtil : NSObject /** * 基础服务的接口都要校验sign */ +(NSMutableDictionary *)GetSignRequestDictionary:(NSMutableDictionary *)params; @end NS_ASSUME_NONNULL_END Demo/EZOpensdk_iOS_4.15.1_build20201104/Demo/EZOpenSDKDemo/Global/EZHttpUtil.m
New file @@ -0,0 +1,84 @@ // // EZHttpUtil.m // EZOpenSDKDemo // // Created by 陈嘉乐 on 2021/2/26. // Copyright © 2021 hikvision. All rights reserved. // #import "EZHttpUtil.h" #import <Foundation/Foundation.h> #import <CommonCrypto/CommonDigest.h> #define APP_KEY @"HDL-HOME-APP-TEST" #define SECRET_KEY @"WeJ8TY88vbakCcnvH8G1tDUqzLWY8yss" @implementation EZHttpUtil +(NSMutableDictionary *)GetSignRequestDictionary:(NSMutableDictionary *)params{ if(params == NULL){ params =[NSMutableDictionary dictionary]; } [params setValue:APP_KEY forKey:@"appKey"]; [params setValue:@"" forKey:@"timestamp"]; //1.对KEY升序 NSArray *keyArray = [params allKeys]; NSArray *sortKeyArray = [keyArray sortedArrayUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) { return [obj1 compare:obj2 options:NSNumericSearch]; }]; //2.2 拼接按URL键值对 NSString *newString = @""; for(NSString *key in sortKeyArray){ if(params[key] != NULL){ NSString *valueStr = params[key]; //检测当前参数是否需要参与校验 if([self IfValueNeedSign:valueStr]){ newString = [newString stringByAppendingString:[NSString stringWithFormat:@"%@=%@&", key,valueStr]]; } } } //2.3 拼接SECRET_KEY newString = [newString substringToIndex:[newString length] - 1]; newString = [ newString stringByAppendingString: SECRET_KEY]; //2.4 MD5转换+转小写 if(newString == nil || newString == NULL){ newString = @""; } NSString* signstr = [self signMD5Encrypt:newString]; [params setValue:signstr forKey:@"sign"]; return params; } + (NSString*)signMD5Encrypt:(NSString *)str { const char *cStr = [str UTF8String]; unsigned char digest[CC_MD5_DIGEST_LENGTH]; CC_MD5( cStr, strlen(cStr),digest ); NSMutableString *result = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2]; for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) [result appendFormat:@"%02x", digest[i]]; return result; } /// <summary> /// 判断当前值是否需要参与签名,保持跟云端一致 /// 空字符串不参与 /// 数组,集合,对象不参与 /// </summary> /// <param name="valueStr"></param> /// <returns></returns> +(bool)IfValueNeedSign:(NSString *)valueStr{ if (( (valueStr == nil || [valueStr isKindOfClass:[NSNull class]] || valueStr.length == 0))//判空字符 || ([[valueStr substringToIndex:1] isEqual:@"{"])//判断是否为对象 || ([[valueStr substringToIndex:1] isEqual:@"["])//判断是否为数组 ) { return false; } return true; } @end Demo/EZOpensdk_iOS_4.15.1_build20201104/Demo/EZOpenSDKDemo/Global/EZSDK.h
New file @@ -0,0 +1,67 @@ // // EZSDK.h // EZSDK // // Created by 陈嘉乐 on 2021/1/27. // #import <Foundation/Foundation.h> @interface EZSDK : NSObject /** 初始化SDK 传入国内版key 和海外版globalAppKey */ + (BOOL)initLibWithAppKey:(NSString *)appKey globalAppKey:(NSString *)globalAppKey; /** 设置SDK的accessToken */ +(void)setEZAccessToken:(NSString *) accessToken; /** 直接跳转到萤石摄像头列表 */ +(void)go2EZvizMonitor; /** 跳转添加添加设备 */ +(void)addEzvizMonitor; /** 查看视频监控直播 */ +(void)Play:(NSObject*)deviceInfo; /** 打开摄像头设置页面 */ +(void)setting:(NSObject*)deviceInfo; /** 回放播放历史 */ +(void)playBackVideo:(NSObject*)deviceInfo; #pragma mark -接口 /** * @since 河东获取子账号token的接口 * * @param block 回调block */ + (NSURLSessionDataTask *)getChildToken:(void (^)(NSString *accessToken))block; /** * @since 河东添加设备的接口 * 根据设备序列号和设备验证码添加设备接口 * * @param deviceSerial 设备序列号 * @param verifyCode 设备验证码 * @param completion 回调block,error为空时表示添加成功 * * @return operation */ + (NSURLSessionDataTask *)addDeviceByHDL:(NSString *)deviceSerial verifyCode:(NSString *)verifyCode completion:(void (^)(NSError *error))completion; @end Demo/EZOpensdk_iOS_4.15.1_build20201104/Demo/EZOpenSDKDemo/Global/EZSDK.m
New file @@ -0,0 +1,462 @@ // // 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 "AFNetworking.h" #import <Foundation/Foundation.h> #import <CommonCrypto/CommonDigest.h> #define API_POST_EZ_AddDevice @"/home-wisdom/platform/child/device/add" #define API_POST_EZ_GetChildToken @"/home-wisdom/platform/childToken" #define APP_KEY @"HDL-HOME-APP-TEST" #define SECRET_KEY @"WeJ8TY88vbakCcnvH8G1tDUqzLWY8yss" @implementation EZSDK /** 初始化SDK 传入国内版key 和海外版globalAppKey */ + (BOOL)initLibWithAppKey:(NSString *)appKey globalAppKey:(NSString *)globalAppKey { static BOOL isHavelibInit=NO; if (!isHavelibInit) { // isHavelibInit=YES; // NSLog(@"第一次初始化萤石库"); if (!LanguageIsChinese) { //海外版 isHavelibInit = [EZGlobalSDK initLibWithAppKey:globalAppKey]; NSLog(@"海外版key--%@",globalAppKey); }else{ isHavelibInit = [EZOpenSDK initLibWithAppKey:appKey]; NSLog(@"国内版key--%@", appKey); } [EZHCNetDeviceSDK initSDK]; [EZOPENSDK enableP2P:YES]; [EZOPENSDK setDebugLogEnable:YES]; NSLog(@"EZOpenSDK Version = %@", [EZOPENSDK getVersion]); } return isHavelibInit; } /** 设置SDK的accessToken */ +(void)setEZAccessToken:(NSString *) accessToken { [[GlobalKit shareKit] setAccessToken:accessToken]; [EZOPENSDK setAccessToken:accessToken]; } //获取当前屏幕显示的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 { // 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********"); } /** 跳转添加添加设备 */ +(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以下扫码功能请自行实现"); } } /** 查看视频监控直播 */ +(void)Play:(NSObject*)deviceInfo { 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]; } /** 打开摄像头设置页面 */ +(void)setting:(NSObject*)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:(NSObject*)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]; } //+(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"); // }]; // } //} #pragma mark -接口请求部分 /** * @since 河东获取子账号token的接口 * * @param block 回调block */ + (NSURLSessionDataTask *)getChildToken:(void (^)(NSString *accessToken))block{ //1,创建你得请求url NSString *URL = @""; if([GlobalKit shareKit].GlobalRequestHttpsHost == NULL){ URL = @"https://test-gz.hdlcontrol.com"; } URL = [NSString stringWithFormat:@"%@%@", URL, API_POST_EZ_GetChildToken]; //2.设置请求参数 NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; parameters = [self GetSignRequestDictionary:parameters]; NSURLSessionDataTask*task=nil; AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]; AFHTTPResponseSerializer *responseSerializer = [AFHTTPResponseSerializer serializer]; manager.responseSerializer = responseSerializer; NSMutableURLRequest * request = [[AFJSONRequestSerializer serializer] requestWithMethod:@"post" URLString:URL parameters:parameters error:nil]; [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; [request setValue:@"application/json" forHTTPHeaderField:@"Accept"]; [request setValue:GlobalKit.shareKit.hdlAccessToken forHTTPHeaderField:@"Authorization"]; [[manager dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) { //4.解析拿到的响应数据 NSLog(@"%@",[[NSString alloc]initWithData:responseObject encoding:NSUTF8StringEncoding]); if (block) { NSString * token = @""; block (token); } }]resume]; return task; } /** * @since 河东添加设备的接口 * 根据设备序列号和设备验证码添加设备接口 * * @param deviceSerial 设备序列号 * @param verifyCode 设备验证码 * @param completion 回调block,error为空时表示添加成功 * * @return operation */ + (NSURLSessionDataTask *)addDeviceByHDL:(NSString *)deviceSerial verifyCode:(NSString *)verifyCode completion:(void (^)(NSError *error))completion{ //1,创建你得请求url NSString *URL = @""; if([GlobalKit shareKit].GlobalRequestHttpsHost == NULL){ URL = @"https://test-gz.hdlcontrol.com"; } URL = [NSString stringWithFormat:@"%@%@",URL, @"/smart-footstone/region/regionByAccount"]; //2.设置请求参数 NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; // [parameters setValue:deviceSerial forKey:@"deviceSerial"]; // [parameters setValue:verifyCode forKey:@"verifyCode"]; // parameters[@"deviceSerial"] = deviceSerial; // parameters[@"verifyCode"] = verifyCode; parameters[@"account"] = @"18824864143"; // parameters = [self GetSignRequestDictionary:parameters]; NSURLSessionDataTask*task=nil; AFHTTPSessionManager *manager = [[AFHTTPSessionManager alloc] initWithSessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]; AFHTTPResponseSerializer *responseSerializer = [AFHTTPResponseSerializer serializer]; manager.responseSerializer = responseSerializer; NSMutableURLRequest * request = [[AFJSONRequestSerializer serializer] requestWithMethod:@"post" URLString:URL parameters:parameters error:nil]; [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"]; [request setValue:@"application/json" forHTTPHeaderField:@"Accept"]; [[manager dataTaskWithRequest:request completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error) { // //拿到响应头信息 // NSHTTPURLResponse *res = (NSHTTPURLResponse *)response; //4.解析拿到的响应数据 NSLog(@"%@",[[NSString alloc]initWithData:responseObject encoding:NSUTF8StringEncoding]); if (completion) { // error.code = 105002; completion (error); } }]resume]; return task; } #pragma mark HttpUtil /** * 基础服务的接口都要校验sign */ +(NSMutableDictionary *)GetSignRequestDictionary:(NSMutableDictionary *)params{ if(params == NULL){ params =[NSMutableDictionary dictionary]; } UInt64 recordTime = [[NSDate date] timeIntervalSince1970]*1000; [params setValue:APP_KEY forKey:@"appKey"]; [params setValue:[NSString stringWithFormat:@"%llu",recordTime] forKey:@"timestamp"]; //1.对KEY升序 NSArray *keyArray = [params allKeys]; NSArray *sortKeyArray = [keyArray sortedArrayUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) { return [obj1 compare:obj2 options:NSNumericSearch]; }]; //2.2 拼接按URL键值对 NSString *newString = @""; for(NSString *key in sortKeyArray){ if(params[key] != NULL){ NSString *valueStr = params[key]; //检测当前参数是否需要参与校验 if([self IfValueNeedSign:valueStr]){ newString = [newString stringByAppendingString:[NSString stringWithFormat:@"%@=%@&", key,valueStr]]; } } } //2.3 拼接SECRET_KEY newString = [newString substringToIndex:[newString length] - 1]; newString = [newString stringByAppendingString: SECRET_KEY]; //2.4 MD5转换+转小写 if(newString == nil || newString == NULL){ newString = @""; } NSString* signstr = [self signMD5Encrypt:newString]; [params setValue:signstr forKey:@"sign"]; return params; } /** MD5转换+转小写 */ + (NSString*)signMD5Encrypt:(NSString *)str { const char *cStr = [str UTF8String]; unsigned char digest[CC_MD5_DIGEST_LENGTH]; CC_MD5( cStr, strlen(cStr),digest ); NSMutableString *result = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2]; for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) [result appendFormat:@"%02x", digest[i]]; return result; } /// <summary> /// 判断当前值是否需要参与签名,保持跟云端一致 /// 空字符串不参与 /// 数组,集合,对象不参与 /// </summary> /// <param name="valueStr"></param> /// <returns></returns> +(bool)IfValueNeedSign:(NSString *)valueStr{ if (( (valueStr == nil || [valueStr isKindOfClass:[NSNull class]] || valueStr.length == 0))//判空字符 || ([[valueStr substringToIndex:1] isEqual:@"{"])//判断是否为对象 || ([[valueStr substringToIndex:1] isEqual:@"["])//判断是否为数组 ) { return false; } return true; } @end Demo/EZOpensdk_iOS_4.15.1_build20201104/Demo/EZOpenSDKDemo/Global/GlobalKit.h
@@ -18,6 +18,9 @@ @interface GlobalKit : NSObject @property (nonatomic, copy) NSString *GlobalRequestHttpsHost; @property (nonatomic, copy) NSString *hdlAccessToken; @property (nonatomic, copy) NSString *accessToken; @property (nonatomic, copy) NSString *deviceSerialNo; //设备序列号 @property (nonatomic, copy) NSString *deviceModel; //设备类型字符串 @@ -32,4 +35,7 @@ - (void)clearDeviceInfo; +(void)hello; @end Demo/EZOpensdk_iOS_4.15.1_build20201104/Demo/EZOpenSDKDemo/Global/ResponseData.h
New file @@ -0,0 +1,31 @@ // // ResponseData.h // EZOpenSDKDemo // // Created by 陈嘉乐 on 2021/3/1. // Copyright © 2021 hikvision. All rights reserved. // #import <Foundation/Foundation.h> NS_ASSUME_NONNULL_BEGIN /** */ @interface ResponseData : NSObject /** */ @property (nonatomic, copy) NSString *code; /** */ @property (nonatomic, copy) NSString *message; /** */ @property (nonatomic, copy) NSObject *data; @end NS_ASSUME_NONNULL_END Demo/EZOpensdk_iOS_4.15.1_build20201104/Demo/EZOpenSDKDemo/Global/ResponseData.m
New file @@ -0,0 +1,13 @@ // // ResponseData.m // EZOpenSDKDemo // // Created by 陈嘉乐 on 2021/3/1. // Copyright © 2021 hikvision. All rights reserved. // #import "ResponseData.h" @implementation ResponseData @end Demo/EZOpensdk_iOS_4.15.1_build20201104/Demo/EZOpenSDKDemo/TableViewCells/DeviceListCell.m
@@ -35,7 +35,7 @@ } self.nameLabel.text = [NSString stringWithFormat:@"%@",deviceInfo.deviceName]; [self.cameraImageView sd_setImageWithURL:[NSURL URLWithString:deviceInfo.deviceCover] placeholderImageScale:nil]; [self.cameraImageView sd_setImageWithURL:[NSURL URLWithString:deviceInfo.deviceCover] placeholderImage:[UIImage imageNamed:@"device_default"]]; // [EZOPENSDK capturePicture:cameraInfo.deviceSerial channelNo:cameraInfo.channelNo completion:^(NSString *url, NSError *error) { // if(!error){ // [self.cameraImageView sd_setImageWithURL:[NSURL URLWithString:url]]; Demo/EZOpensdk_iOS_4.15.1_build20201104/Demo/EZOpenSDKDemo/ViewController.m
@@ -9,6 +9,8 @@ #import "ViewController.h" #import "EZSupportViewController.h" #import "DDKit.h" #import "EZSDK.h" #import "MBProgressHUD.h" @interface ViewController () @property (weak, nonatomic) IBOutlet UIButton *ddnsDemoBtn; @@ -26,6 +28,8 @@ self.ddnsDemoBtn.hidden = YES; #endif // Do any additional setup after loading the view, typically from a nib. } - (void)didReceiveMemoryWarning { @@ -45,6 +49,7 @@ // //push摄像头列表的viewController // [self.navigationController pushViewController:instanceVC animated:YES]; [[GlobalKit shareKit] setAccessToken:@"ra.b48ex6o495x0etj76a0a3huh1x91ymvw-8oi8f811ry-15pqyvo-dyuk9nyz4"]; /** * 下面代码功能与以上的注释方法相同 */ @@ -54,13 +59,58 @@ - (IBAction)logout:(id)sender { [EZOPENSDK logout:^(NSError *error) { // [EZOPENSDK logout:^(NSError *error) { // }]; __weak MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; [EZSDK addDeviceByHDL:@"" verifyCode:@"" completion:^(NSError *error) { [hud hide:YES]; if(!error){ NSLog(@"请求成功"); }else{ NSLog(@"请求失败"); // NSLog(@"请求失败%@",error.description); } [self handleTheError:error]; }]; } - (void)handleTheError:(NSError *)error { if (!error) { // [self performSegueWithIdentifier:@"go2WifiResult" sender:nil]; return; } if (error.code == 105002) { UIAlertView *retryAlertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"device_verify_code_wrong", @"验证码错误") message:nil delegate:self cancelButtonTitle:NSLocalizedString(@"cancel", @"取消") otherButtonTitles:NSLocalizedString(@"retry", @"重试"), nil]; retryAlertView.tag = 0xbb; [retryAlertView show]; } else if (error.code == 105000) { [UIView dd_showMessage:NSLocalizedString(@"ad_already_added",@"您已添加过此设备")]; } else if (error.code == 105001) { [UIView dd_showMessage:NSLocalizedString(@"ad_added_by_others",@"此设备已被别人添加")]; } else { [UIView dd_showMessage:NSLocalizedString(@"wifi_add_fail",@"添加失败")]; } } - (IBAction)goAPI:(id)sender { [EZOPENSDK gotoEzvizAppPage:EZPageAlarmList appType:EZEzvizInternational]; // [EZOPENSDK gotoEzvizAppPage:EZPageAlarmList appType:EZEzvizInternational]; // [self performSegueWithIdentifier:@"go2DemoAPI" sender:nil]; }