JLChen
2021-02-03 4715e99a9be1c50d8ec31f594af9ebde18647c94
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
//
//  EZSDK.m
//  EZSDK
//
//  Created by 陈嘉乐 on 2021/1/27.
//
 
#import "EZSDK.h"
#import "DeviceInfo.h"
#import "EZDeviceInfo.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"
 
@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");
//        }];
//    }
//}
 
@end