JLChen
2021-04-30 a5247b61d585627a1a7b1e1f35f34de9f0af9fba
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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
//
//  LCAdvertisementDetailViewController.m
//  LCIphone
//  Owned by peng_qitao on 16/09/20.
//  Created by zhangyp on 16/6/21.
//  Copyright © 2016年 dahua. All rights reserved.
//
 
#import "LCAdvertisementDetailViewController.h"
#import "DHAppConfig.h"
#import <DHBaseModule/DHPubDefine.h>
#import "LCMacro.h"
#import <DHBaseModule/LCNotificationKey.h>
#import "UINavigationItem+LeChange.h"
#import <DHBaseModule/DHModuleConfig.h>
//微信SDK头文件
#import "WXApi.h"
 
#import <sys/utsname.h>
#import "NSString+LeChange.h"
#import <SMBUserModule/DHDataManager.h>
#import <DHBaseModule/UIDevice+IPhoneModel.h>
#import <DHBaseModule/DHMobileInfo.h>
#import <DHBaseModule/DHUserManager.h>
#import <DHBaseModule/LCPermissionHelper.h>
#import <DHBaseModule/NSString+DataConversion.h>
#import <Categories/NSObject+JSON.h>
#import <SMBUserModule/NSString+Account.h>
#import <DHBaseModule/DHWebAuthLoginService.h>
#import <LCWeiKit/LCUserInterface.h>
#import <DHBaseModule/DHBaseModule-Swift.h>
#import <DHHomePageModule/DHHomePageModule-Swift.h>
#import <ContactsUI/CNContactViewController.h>
#import <ContactsUI/CNContactPickerViewController.h>
#import <SMBUserModule/SMBUserModule-Swift.h>
#import <AddressBook/AddressBook.h>
 
#import "LCIphoneAdhocIP-Swift.h"
#import "LCWebLogViewController.h"
 
#define ADVERSEMENT_REFRESH 101
#define ADVERSEMENT_SHARE   102
#define ADVERSEMENT_SAFARI  103
 
#define OPEN_PAGE_MAX       5
 
static NSInteger WebOpenPageNum = 0;
 
#ifdef LECHANGE
@interface LCAdvertisementDetailViewController ()<LCWebQRCodeScannerVCDelegate>
 
@end
#endif
 
@interface LCAdvertisementDetailViewController ()<CNContactViewControllerDelegate, CNContactPickerDelegate, WKScriptMessageHandler>
{
//    UIButton *_shareBtn;
    UIButton *_testShareBtn;   //用来在发测版本显示分享按钮,便于在safari打开
    UITapGestureRecognizer *_tap; //导航栏连点手势,查看前端日志
}
 
@property (nonatomic, copy) NSString *wechatRedirectUrl;
@property (nonatomic, copy) NSString *domainString;
@property (nonatomic, copy) NSString *curUrl;
@property (nonatomic, assign) BOOL isAcceptNotificatin;
@property (nonatomic, assign) BOOL isViewLoaded;//是否已经加载  防止viewDidAppera中onresume在viewdidload后调用
@property (nonatomic, strong) NSNumber *openPageNum;
@property (nonatomic, strong) UIButton *shareBtn;
@property (nonatomic) BOOL shouldShowMore; //是否调用前端的noticeShowMore
@property (nonatomic) BOOL isShowNavi;//保存隐藏navi之前的状态
@end
 
@implementation LCAdvertisementDetailViewController
 
- (void)dealloc
{
    DH_LOG_DEALLOCED
    [[NSNotificationCenter defaultCenter] removeObserver: self];
}
 
- (void)viewDidLoad {
    [super viewDidLoad];
    self.shouldShowMore = NO;
    self.curUrl = self.playUrl;
    // Do any additional setup after loading the view.
    self.isShowNavi = self.navBar.isHidden;
    [self initRightNavigationItem];
 
    self.isAcceptNotificatin = NO;
 
    if (@available(iOS 11.0, *)) {
        self.webView.scrollView.contentInsetAdjustmentBehavior = UIApplicationBackgroundFetchIntervalNever;
    } else {
        self.automaticallyAdjustsScrollViewInsets = false;
    }
 
#ifdef LECHANGE
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(alipayCallBack:) name:LCNotificationAlipayResult object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(weixinPayCallBack:) name:LCNotificationWeixinPayResult object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sendLoginInfoToHtml:) name:LCNotificationLoginSuccessed object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginFailed:) name:LCNotificationLoginFailed object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(closeLogin:) name:LCNotificationTouchLoginClose object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onResume:) name:UIApplicationDidBecomeActiveNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addNewFriendNoti:) name:LCNotificationNewFriendMsg object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(addFriendResult:) name:LCNotificationMyFriendListChanged object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resetViewData) name:DHNotificationResetShopAndDiscovery object:nil];
#endif
    //性能测试打印
    if (![DHAppConfig isDistributionVersion]) {
        objc_setAssociatedObject(self, "time", [NSDate date], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
        NSLog(@"⏱⏱Performance-Analysis-LechangeShop::Start");
    }
    self.wechatRedirectUrl = [DHServerConfig shareInstance].weixinPayScheme;
    self.domainString = [DHServerConfig shareInstance].weixinPayDomain;
    [self.bridge registerHandler:@"testWXInstall" handler:^(id data, WVJBResponseCallback responseCallback) {
        NSLog(@"testWXInstall: %@", data);
        responseCallback([WXApi isWXAppInstalled] ? @"true" : @"false");
    }];
 
    [self.bridge registerHandler:@"getAppVersion" handler:^(id data, WVJBResponseCallback responseCallback) {
        NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
        NSString *appCurVersion = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
        responseCallback(appCurVersion);
    }];
 
    [self.bridge registerHandler:@"getAppName" handler:^(id data, WVJBResponseCallback responseCallback) {
        NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
        NSString *appCurName = [infoDictionary objectForKey:@"CFBundleDisplayName"];
        responseCallback(appCurName);
    }];
 
    id<DHWebAuthLoginService> loginService = [DHModule implForService:@protocol(DHWebAuthLoginService)];
    NSString *loginSignUrl = [loginService getSignUrlWithSrcUrl:self.playUrl];
    loginSignUrl = loginSignUrl == nil ? self.playUrl : loginSignUrl;
 
    [self jsAndOcInteraction:loginSignUrl];
 
    [self configWebviewUserAgent];
}
 
- (void)configWebviewUserAgent
{
    __weak typeof(self) weakSelf = self;
    if (@available(iOS 12.0, *)) {
        NSString *baseAgent = [self.webView valueForKey:@"applicationNameForUserAgent"];
        NSString *userAgent = [NSString stringWithFormat:@"%@ Imou", baseAgent];
        [self.webView setValue:userAgent forKey:@"applicationNameForUserAgent"];
    }
 
    [self.webView evaluateJavaScript:@"navigator.userAgent" completionHandler:^(id result, NSError *error) {
        NSString *oldAgent = result;
        if ([oldAgent rangeOfString:@"Imou"].location != NSNotFound) {
            return;
        }
 
        NSString *newAgent = [NSString stringWithFormat:@"%@ %@", oldAgent, @"Imou"];
        NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:newAgent, @"UserAgent", nil];
 
        [[NSUserDefaults standardUserDefaults] registerDefaults:dictionary];
        [[NSUserDefaults standardUserDefaults] synchronize];
 
        if (@available(iOS 9.0, *)) {
            [weakSelf.webView setCustomUserAgent:newAgent];
        } else {
            [weakSelf.webView setValue:newAgent forKey:@"applicationNameForUserAgent"];
        }
    }];
}
 
#pragma mark -- JS和OC交互的方法
- (void)jsAndOcInteraction:(NSString *)signUrl
{
    //拼接clientUA
    NSMutableDictionary *clientUADic = [[NSMutableDictionary alloc]init];
 
    NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
    NSString *appCurVersion = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
    NSString *version = [NSString stringWithFormat:@"V%@", appCurVersion];
 
    NSString *idfv = [DHDataManager sharedInstance].terminalId;
 
    [clientUADic setObject:@"phone" forKey:@"clientType"];
    [clientUADic setObject:version forKey:@"clientVersion"];
    [clientUADic setObject:[DHServerConfig shareInstance].protocolVersion forKey:@"clientProtocolVersion"];//
    [clientUADic setObject:@"IOS" forKey:@"clientOS"];
    [clientUADic setObject:DH_CLIENT_OS_VERSION forKey:@"clientOV"];
    [clientUADic setObject:[UIDevice lc_iPhoneType] forKey:@"terminalModel"];
 
    [clientUADic setObject:idfv forKey:@"terminalId"];
    [clientUADic setObject:[DHServerConfig shareInstance].app_id forKey:@"appid"];
 
    [clientUADic setObject:[NSString dh_currentLanguageCode] forKey:@"language"];
    [clientUADic setObject:[NSNumber numberWithLongLong:[DHDataManager sharedInstance].userId] forKey:@"userId"];//
 
    [clientUADic setObject:[DHServerConfig shareInstance].project_id forKey:@"project"];
    //[clientUADic setObject:[DHServerConfig shareInstance].caFileName forKey:@"fileName"];
    NSString *clientUAStr = [NSString lc_dictionaryToJson:clientUADic];
    NSString *clientUABase64 = [clientUAStr lc_base64String];
 
    //公共JS方法,用于向网页传递信息
    [self.bridge registerHandler:@"getClientInfo" handler:^(id data, WVJBResponseCallback responseCallback) {
        NSMutableDictionary *infoDic = [[NSMutableDictionary alloc]init];
 
        NSString *versions = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
        NSString *versionTime = [NSString stringWithFormat:@"V%@", versions];
 
        [infoDic setValue:@"phone" forKey:@"clientType"];//设备类型
        [infoDic setValue:versionTime forKey:@"clientVersion"];//版本号+发测时间
        [infoDic setValue:@"IOS" forKey:@"clientOS"];//手机系统
        [clientUADic setObject:DH_CLIENT_OS_VERSION forKey:@"clientOV"];
        [infoDic setValue:[UIDevice lc_iPhoneType] forKey:@"terminalModel"];//手机型号
        NSString *infoJson = [NSString lc_dictionaryToJson:infoDic];
 
        responseCallback(infoJson);
    }];
 
    __weak typeof(self) weakSelf = self;
 
    //直播和商城JS调用OC的方法  免登录接口,已登录返回免登录信息,未登录返回空
    [self.bridge registerHandler:@"getLoginStatus" handler:^(id data, WVJBResponseCallback responseCallback) {
        if ([DHDataManager sharedInstance].isLogin == YES) {
            NSString *tempUrl = weakSelf.curUrl;
            if ([data isKindOfClass:[NSString class]]) {
                NSString *dataStr = data;
 
                if (dataStr.length > 0) {
                    tempUrl = dataStr;
                }
            }
 
            id<DHWebAuthLoginService> loginService = [DHModule implForService:@protocol(DHWebAuthLoginService)];
            NSString *matchUrl = [loginService getSignUrlWithSrcUrl:tempUrl];
            matchUrl = matchUrl == nil ? tempUrl : matchUrl;
 
            NSString *removeLoginInfoUrl = [[matchUrl stringByReplacingOccurrencesOfString:tempUrl withString:@""] lc_base64String];
 
            responseCallback(removeLoginInfoUrl);
            return;
        }
        responseCallback(@"");
    }];
 
#ifdef LECHANGE
 
    //直播和商城JS调用OC的方法  免登录接口,已登录返回免登录信息,未登录返回空,并去登录
    [self.bridge registerHandler:@"goLogin" handler:^(id data, WVJBResponseCallback responseCallback) {
        weakSelf.isAcceptNotificatin = YES;
 
        if ([DHDataManager sharedInstance].isLogin == YES) {
            responseCallback([signUrl lc_base64String]);
            return;
        }
        responseCallback(@"");
        //跳转到登录页面
 
        NSString *urlString = data;
        if ([NSString lc_isEmpty:urlString] && ![NSString lc_isEmpty:weakSelf.webView.URL.absoluteString]) {
            urlString = weakSelf.webView.URL.absoluteString;
        }
        weakSelf.curUrl = urlString;
 
        dispatch_async(dispatch_get_main_queue(), ^{
                           UIWindow *window = [[UIApplication sharedApplication].delegate window];
                           LCTabBarController *tabBarViewController = (LCTabBarController *)window.rootViewController;
                           UIViewController *vc = tabBarViewController.presentedViewController;
                           if (window != nil && [window.rootViewController isKindOfClass:[LCTabBarController class]]) {
                               if ([vc isKindOfClass:NSClassFromString(@"DHLoginViewController")]) {
                                   [vc dismissViewControllerAnimated:NO completion:nil];
                               }
                           }
                           UIStoryboard *currentStoryboard = [UIStoryboard storyboardWithName:@"User" bundle:[NSBundle mainBundle]];
                           UIViewController *loginVC = [currentStoryboard instantiateViewControllerWithIdentifier:@"login"];
                           //UIViewController *loginVC = [DHRouter objectForURL:@"/lechange/login/loginViewController"];
 
                           [weakSelf presentViewController:loginVC animated:YES completion:nil];
                       });
    }];
#endif
 
    //云存储鉴权JS调用OC的方法
    [self.bridge registerHandler:@"getCloudLoginInfo" handler:^(id data, WVJBResponseCallback responseCallback) {
        NSMutableDictionary *infoDic = [[NSMutableDictionary alloc]init];
        //        NSString *username = [NSString stringWithFormat:@"uuid\%@",[DHDataManager sharedInstance].tokenUserName];
        NSString *username = [DHDataManager sharedInstance].tokenUserName;
        NSString *token = [DHDataManager sharedInstance].accessToken;
 
        if (![NSString lc_isEmpty:username]) {
            [infoDic setObject:username forKey:@"username"];
        }
        if (![NSString lc_isEmpty:token]) {
            [infoDic setObject:token forKey:@"password"];
        }
        [infoDic setObject:clientUABase64 forKey:@"clientUA"];
        [infoDic setObject:[DHDataManager sharedInstance].webServiceDomain forKey:@"host"];
 
        if (![NSString lc_isEmpty:weakSelf.curDeviceID] && ![NSString lc_isEmpty:weakSelf.curChannelID]) {
            [infoDic setObject:weakSelf.curDeviceID forKey:@"deviceId"];//进入单个设备云存储页面需要传入设备序列号
            [infoDic setObject:weakSelf.curChannelID forKey:@"channelId"];//进入单个设备云存储页面需要传入通道号,单通道设备默认传0
        }
 
        //配件传deviceId、apId
        if (![NSString lc_isEmpty:weakSelf.curDeviceID] && ![NSString lc_isEmpty:weakSelf.curApID]) {
            [infoDic setObject:weakSelf.curDeviceID forKey:@"deviceId"];
            [infoDic setObject:weakSelf.curApID forKey:@"apId"];
        }
 
        NSString *infoJson = [NSString lc_dictionaryToJson:infoDic];
        responseCallback(infoJson);
    }];
 
    //
    [self.bridge registerHandler:@"noticeShowMore" handler:^(id data, WVJBResponseCallback responseCallback) {
        NSLog(@"%@", data);
    }];
 
    //云存储状态改变通知 JS调用OC的方法
    [self.bridge registerHandler:@"noticeNative" handler:^(id data, WVJBResponseCallback responseCallback) {
        NSDictionary *cloudStateChangeDic;
 
        if ([data isKindOfClass:[NSDictionary class]]) {
            if ([[(NSDictionary *)data objectForKey:@"action"] isEqualToString:@"getUserPushMessageDetail"]) {
                NSString *infoJson = weakSelf.templateParam;
                responseCallback(infoJson);
            }
 
            //DTS000285608 未进行赋值问题
            cloudStateChangeDic = (NSDictionary *)data;
        } else if ([data isKindOfClass:[NSString class]]) {
            cloudStateChangeDic = [weakSelf dictionaryWithJsonString:data];
        }
 
        if ([[cloudStateChangeDic objectForKey:@"action"] isEqualToString:@"openPage"]) {//状态改变,刷新缓存
            dispatch_async(dispatch_get_main_queue(), ^{
                               NSDictionary *dict = [cloudStateChangeDic objectForKey:@"param"];
                               NSString *funcUrl = dict[@"funcUrl"];
                               if (WebOpenPageNum >= OPEN_PAGE_MAX) {
                                   NSURL *tempUrl = [NSURL URLWithString:funcUrl];
                                   NSURLRequest *request = [NSURLRequest requestWithURL:tempUrl cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0];
                                   [weakSelf.webView loadRequest:request];
                               } else {
                                   WebOpenPageNum = WebOpenPageNum + 1;
                                   LCAdvertisementDetailViewController *vc = [LCAdvertisementDetailViewController new];
                                   vc.isOpenPage = YES;
                                   vc.playUrl = funcUrl;
                                   vc.isShowShareButton = YES;
                                   vc.hidesBottomBarWhenPushed = YES;
                                   [weakSelf.navigationController pushViewController:vc animated:YES];
                               }
                           });
        } else if ([[cloudStateChangeDic objectForKey:@"action"] isEqualToString:@"goScanPage"]) {
            //跳转到二维码扫描页
            dispatch_async(dispatch_get_main_queue(), ^{
                               [LCPermissionHelper requestCameraPermission:^(BOOL granted) {
                                   if (granted) {
                                       NSDictionary *dict = [cloudStateChangeDic objectForKey:@"param"];
                                       NSString *description = dict[@"description"];
                                       NSString *iconUrl = dict[@"icon"];
 
                                       LCWebQRCodeScannerVC *vc = [LCWebQRCodeScannerVC new];
                                       vc.delegate = weakSelf;
                                       [vc.imageView lc_setImageWithUrl:iconUrl];
                                       vc.tipsLbl.text = description;
                                       [weakSelf presentViewController:vc animated:YES completion:nil];
                                   }
                               }];
                           });
        } else if ([[cloudStateChangeDic objectForKey:@"action"] isEqualToString:@"goFamilyPhoto"]) {
        } else if ([[cloudStateChangeDic objectForKey:@"action"] isEqualToString:@"cloudStrategyStateChange"]) {//状态改变,刷新缓存
            dispatch_async(dispatch_get_main_queue(), ^{
                               NSDictionary *dict = [cloudStateChangeDic objectForKey:@"param"];
                               NSNotification *notification = [NSNotification notificationWithName:LCNotificationCloudStoragePaySuccess object:nil userInfo:dict];
                               //通过通知中心发送通知
                               [[NSNotificationCenter defaultCenter] postNotification:notification];
                           });
        } else if ([[cloudStateChangeDic objectForKey:@"action"] isEqualToString:@"logout"]) {//token失效,帐号被踢
            NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:@"GetDeviceList", @"ApiName", @"user get out", @"Desc", nil];
            LCError *error = [[LCError alloc] initWithCode:1112 errorInfo:userInfo];
 
            dispatch_async(dispatch_get_main_queue(), ^{
                               [[NSNotificationCenter defaultCenter] postNotificationName:LCNotificationPasswordChange object:error];
                           });
        } else if ([[cloudStateChangeDic objectForKey:@"action"] isEqualToString:@"updateUserInfo"]) {
            NSDictionary *dict = [cloudStateChangeDic objectForKey:@"param"];
 
            if (dict) {
                NSString *userId = dict[@"userId"];
 
                // 绑定成功后需要更新userID
                [DHDataManager sharedInstance].userId = userId.integerValue;
 
                //更新用户信息
                [LCUserInterface saas_getUserInfoSuccess:^(LCUserInfo *userInfo) {
                    [DHDataManager sharedInstance].userId = userInfo.userId;
                    [DHUserManager shareInstance].nickname = userInfo.nickname;
                    [DHUserManager shareInstance].phone = userInfo.phoneNumber;
                    [DHUserManager shareInstance].email = userInfo.email;
                    [DHUserManager shareInstance].avatarUrl = userInfo.avatarUrl;
                    [DHUserManager shareInstance].avatarMd5 = userInfo.avatarMD5;
                    [DHUserManager shareInstance].countryCode = userInfo.country;
 
                    //发送第三方账号绑定成功的通知
                    [[NSNotificationCenter defaultCenter] postNotificationName:LCNotificationThirdBindAccountSuccess object:nil];
 
                    NSLog(@"H5 bind phoneNumber, getUserInfo success");
                } failure:^(LCError *error) {
                    NSLog(@"H5 bind phoneNumber, getUserInfo failure");
                }];
            }
        } else if ([[cloudStateChangeDic objectForKey:@"action"] isEqualToString:@"AIHumanReminderStrategyBuy"]) {
            // 通知
            [DHDataManager sharedInstance].isTimePhotoEnable = @"true";
            [[NSNotificationCenter defaultCenter] postNotificationName:LCNotificationQueryTimePhoto object:nil];
        } else if ([[cloudStateChangeDic objectForKey:@"action"] isEqualToString:@"goAccountSafe"]) {
            [weakSelf handleAccountSafe:cloudStateChangeDic];
        } else if ([[cloudStateChangeDic objectForKey:@"action"] isEqualToString:@"goFriendApply"]) {
            [weakSelf handleFriendApply:cloudStateChangeDic];
        } else if ([[cloudStateChangeDic objectForKey:@"action"] isEqualToString:@"deviceShareStateChange"]) {
            [weakSelf handleDeviceShareStateChange:cloudStateChangeDic];
        } else if ([[cloudStateChangeDic objectForKey:@"action"] isEqualToString:@"apShareStateChange"]) {
            [weakSelf handleApShareStateChange:cloudStateChangeDic];
        } else if ([[cloudStateChangeDic objectForKey:@"action"] isEqualToString:@"goDefenceSetting"]) {
            [weakSelf handleDefenceSet:cloudStateChangeDic];
        } else if ([[cloudStateChangeDic objectForKey:@"action"] isEqualToString:@"goFamily"]) {
        } else if ([[cloudStateChangeDic objectForKey:@"action"] isEqualToString:@"addContact"]) {
#ifdef LECHANGE
            NSDictionary *dic = [cloudStateChangeDic objectForKey:@"param"];
            NSString *name = [dic objectForKey:@"name"];
            NSArray *numbers = [dic objectForKey:@"numbers"];
 
            NSMutableDictionary *infoDic = [[NSMutableDictionary alloc] init];
 
            [LCPermissionHelper requestContacePermission:^(BOOL granted) {
                if (granted) {
                    if (![weakSelf isExitContact:name]) {
                        [weakSelf addNewContaceName:name phoneNumbers:numbers];
                    }
                    [infoDic setObject:@"true" forKey:@"result"];
                    NSString *infoJson = [NSString lc_dictionaryToJson:infoDic];
                    [weakSelf callBack:infoJson];
                }
            } complete:^(NSInteger index) {
                if (index == 1) {
                    [infoDic setObject:@"noloading" forKey:@"result"];
                    NSString *infoJson = [NSString lc_dictionaryToJson:infoDic];
                    [weakSelf callBack:infoJson];
                } else {
                    [infoDic setObject:@"false" forKey:@"result"];
                    NSString *infoJson = [NSString lc_dictionaryToJson:infoDic];
                    [weakSelf callBack:infoJson];
                }
            }];
#endif
        } else if ([[cloudStateChangeDic objectForKey:@"action"] isEqualToString:@"accountCancellation"]) {
            //注销成功 通知App 跳转到登录界面 账号清空
            [weakSelf handleAccountCancellation:cloudStateChangeDic];
        } else if ([[cloudStateChangeDic objectForKey:@"action"] isEqualToString:@"transferDeviceSuccess"]) {
            //设备转移成功,返回到App页面
            [weakSelf.navigationController popToRootViewControllerAnimated:YES];
 
            //刷新首页数据:参考云存储实现,需要知道设备id、通道id
            NSDictionary *dict = [cloudStateChangeDic objectForKey:@"param"];
            [[NSNotificationCenter defaultCenter] postNotificationName:LCNotificationTransferDeviceSuccess object:nil userInfo:dict];
        } else if ([[cloudStateChangeDic objectForKey:@"action"] isEqualToString:@"getContactPhoneDetail"]) {
            //唤起手机通讯录
            [weakSelf handleShowContact];
        } else if ([[cloudStateChangeDic objectForKey:@"action"] isEqualToString:@"refreshMyFriendRedDot"]) {
        } else if ([[cloudStateChangeDic objectForKey:@"action"] isEqualToString:@"showMoreButton"]) {
            //唤起手机通讯录
            NSDictionary *dict = [cloudStateChangeDic objectForKey:@"param"];
            BOOL canShow = [dict[@"canShow"] boolValue];
            weakSelf.shareBtn.hidden = !canShow;
            weakSelf.shouldShowMore = YES;
        } else if ([[cloudStateChangeDic objectForKey:@"action"] isEqualToString:@"wechatFriends"]) {
        }
        if ([[cloudStateChangeDic objectForKey:@"action"] isEqualToString:@"wechatMoments"]) {
        }
        if ([[cloudStateChangeDic objectForKey:@"action"] isEqualToString:@"openWithBrowser"]) {
            //浏览器打开
 
            if (weakSelf.webView.URL.absoluteString.length != 0) {
                [[UIApplication sharedApplication ] openURL:weakSelf.webView.URL];
            } else {
                [[UIApplication sharedApplication ] openURL:[NSURL URLWithString:weakSelf.playUrl]];
            }
        }
        if ([[cloudStateChangeDic objectForKey:@"action"] isEqualToString:@"backHome"]) {
            //回到首页
 
            NSArray<UIViewController *> *list = weakSelf.navigationController.viewControllers;
            UIViewController *target = nil;
            for (UIViewController *vc in list) {
                if ([vc isKindOfClass:[weakSelf class]]) {
                    LCAdvertisementDetailViewController *adVC = (LCAdvertisementDetailViewController *)vc;
                    if (adVC.isOpenPage) {
                        continue;
                    } else {
                        target = adVC;
                        break;
                    }
                } else {
                    target = vc;
                }
            }
            if (target) {
                [weakSelf.navigationController popToViewController:target animated:YES];
            }
        }
    }];
 
    [self.bridge registerHandler:@"getOauthInfo" handler:^(id data, WVJBResponseCallback responseCallback) {
        NSMutableDictionary *infoDic = [[NSMutableDictionary alloc]init];
        NSString *username = [DHDataManager sharedInstance].tokenUserName;
        NSString *token = [DHDataManager sharedInstance].accessToken;
 
        if (![NSString lc_isEmpty:username]) {
            [infoDic setObject:username forKey:@"username"];
        } else {
            [infoDic setObject:[DHServerConfig shareInstance].dh_ak forKey:@"username"];
        }
 
        if (![NSString lc_isEmpty:token]) {
            [infoDic setObject:token forKey:@"password"];
        } else {
            [infoDic setObject:[[DHServerConfig shareInstance].dh_sk lc_base64String] forKey:@"password"];
        }
 
        [infoDic setObject:clientUABase64 forKey:@"clientUA"];
 
        NSString *infoJson = [NSString lc_dictionaryToJson:infoDic];
        responseCallback(infoJson);
    }];
 
    [self.bridge registerHandler:@"applySignIn" handler:^(id data, WVJBResponseCallback responseCallback) {
        dispatch_async(dispatch_get_main_queue(), ^{
                           weakSelf.isAcceptNotificatin = YES;
                           UIWindow *window = [[UIApplication sharedApplication].delegate window];
                           UIViewController *tabBarViewController = window.rootViewController;
                           if (window != nil && [tabBarViewController isKindOfClass:NSClassFromString(@"LCTabBarController")]) {
                               UIViewController *vc = tabBarViewController.presentedViewController;
                               if ([vc isKindOfClass:NSClassFromString(@"DHLoginViewController")]) {
                                   [vc dismissViewControllerAnimated:NO completion:nil];
                               }
                           }
 
                           UIStoryboard *currentStoryboard = [UIStoryboard storyboardWithName:@"User" bundle:[NSBundle mainBundle]];
                           UIViewController *loginVC = [currentStoryboard instantiateViewControllerWithIdentifier:@"login"];
                           if (loginVC) {
                               [weakSelf presentViewController:loginVC animated:YES completion:nil];
                           }
                       });
    }];
    //SMB
    //注册选择部门
    [self.bridge registerHandler:@"selectDepartment" handler:^(id data, WVJBResponseCallback responseCallback) {
        dispatch_async(dispatch_get_main_queue(), ^{
                           [[NSNotificationCenter defaultCenter] postNotificationName:SMBNotificationSelectDepartment object:data];
                       });
    }];
 
    //注册选择部门列表
    [self.bridge registerHandler:@"selectDepartmentList" handler:^(id data, WVJBResponseCallback responseCallback) {
        dispatch_async(dispatch_get_main_queue(), ^{
                           [[NSNotificationCenter defaultCenter] postNotificationName:SMBNotificationSelectDepartmentList object:data];
                       });
    }];
 
    //注册隐藏navi
    [self.bridge registerHandler:@"hideNavigationBar" handler:^(id data, WVJBResponseCallback responseCallback) {
        dispatch_async(dispatch_get_main_queue(), ^{
                           NSString * hide = (NSString *)(NSDictionary *)data[@"param"][@"hiddden"];
                           if ([hide isEqualToString:@"false"]) {
                               self.navBar.hidden = NO;
                           } else {
                               self.navBar.hidden = YES;
                           }
                       });
    }];
}
 
- (void)addNewContaceName:(NSString *)name phoneNumbers:(NSArray<NSDictionary *> *)phoneNumbers {
}
 
- (CNMutableContact *)crateServiceContact:(NSString *)name phoneNumber:(NSArray<NSDictionary *> *)phoneNumbers {
    CNMutableContact *contact = [[CNMutableContact alloc] init];
    contact.organizationName = name;
 
    CNPhoneNumber *mobileNumber = [[CNPhoneNumber alloc] initWithStringValue:[phoneNumbers.firstObject objectForKey:@"phone"]];
    CNLabeledValue *mobilePhone = [[CNLabeledValue alloc] initWithLabel:CNLabelPhoneNumberMobile value:mobileNumber];
    CNPhoneNumber *secondMobileNumber = [[CNPhoneNumber alloc] initWithStringValue:[phoneNumbers.lastObject objectForKey:@"phone"]];
    CNLabeledValue *secondMobilePhone = [[CNLabeledValue alloc] initWithLabel:CNLabelPhoneNumberiPhone value:secondMobileNumber];
    contact.phoneNumbers = @[mobilePhone, secondMobilePhone];
    return contact;
}
 
- (BOOL)addContact:(CNMutableContact *)contact phoneNumber:(NSString *)name {
    if ([self isExitContact:name]) {
        return false;
    }
 
    // 创建联系人请求
    CNSaveRequest *saveRequest = [[CNSaveRequest alloc] init];
    [saveRequest addContact:contact toContainerWithIdentifier:nil];
    // 写入联系人
    CNContactStore *store = [[CNContactStore alloc] init];
    return [store executeSaveRequest:saveRequest error:nil];
}
 
- (CNContact *)isExitContact:(NSString *)organizationName {
    CNContactStore *store = [[CNContactStore alloc] init];
    //检索条件
    NSPredicate *predicate = [CNContact predicateForContactsMatchingName:organizationName];
    //过滤的条件 , ,CNContactEmailAddressesKey,, [CNContactFormatter descriptorForRequiredKeysForStyle:CNContactFormatterStyleFullName]
    NSArray *keysToFetch = @[CNContactEmailAddressesKey, [CNContactFormatter descriptorForRequiredKeysForStyle:CNContactFormatterStyleFullName]];
    NSArray *contact = [store unifiedContactsMatchingPredicate:predicate keysToFetch:keysToFetch error:nil];
    return [contact firstObject];
}
 
- (void)updateContact:(CNMutableContact *)contact {
    // 创建联系人请求
    CNSaveRequest *saveRequest = [[CNSaveRequest alloc] init];
    [saveRequest updateContact:contact];
    // 重新写入
    CNContactStore *store = [[CNContactStore alloc] init];
    NSError *error = nil;
    BOOL saveStatus = [store executeSaveRequest:saveRequest error:&error];
    if (saveStatus == NO) {
        NSLog(@"%@", error);
    }
}
 
- (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString {
    if (jsonString == nil) {
        return nil;
    }
    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *err;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
    if (err) {
        NSLog(@"json解析失败:%@", err);
        return nil;
    }
    return dic;
}
 
- (void)viewDidAppear:(BOOL)animated
{
    self.isAcceptNotificatin = NO;
    [super viewDidAppear:YES];
 
    if (self.disableLockScreen) {
        [UIApplication sharedApplication].idleTimerDisabled = YES;
    }
 
    if (self.isViewLoaded) {
        [self.bridge callHandler:@"noticeWebviewStatus" data:@{ @"status": @"onResume" }.dh_jsonString responseCallback:^(id responseData) {
            NSLog(@"oc请求js - noticeWebviewStatus 后接受的回调结果:%@", responseData);
        }];
    }
    self.isViewLoaded = YES;
}
 
- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    [UIApplication sharedApplication].idleTimerDisabled = NO;
    self.navBar.hidden = self.isShowNavi;
}
 
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    // 非线上版本打开前端日志
    if (![DHAppConfig isDistributionVersion]) {
//        [self openWebLog];
    }
}
 
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    // 非线上版本关闭前端日志
    if (![DHAppConfig isDistributionVersion]) {
        [self stopWebLog];
    }
}
 
#pragma mark - Navigation
- (void)initRightNavigationItem
{
    _testShareBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _testShareBtn.isAccessibilityElement = YES;
    [_testShareBtn setTitle:@"⚠️" forState:UIControlStateNormal];
    [_testShareBtn addTarget:self action:@selector(onRightShareBtnClick:) forControlEvents:UIControlEventTouchUpInside];
 
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.isAccessibilityElement = YES;
    button.accessibilityIdentifier = @"buttonInInitRightNavItemOfPlaybackCloudVC";
    //    button.frame = CGRectMake(0, 0, 40, 40);
 
    [button setImage:DH_IMAGENAMED(@"common_image_nav_moreinfo") forState:UIControlStateNormal];
    [button setImage:DH_IMAGENAMED(@"common_image_nav_moreinfo") forState:UIControlStateHighlighted];
    [button addTarget:self action:@selector(onRightShareBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    _shareBtn = button;
 
    if (self.isShowShareButton) {
        self.navigationItem.lc_rightBarButtons = @[_shareBtn];
    }
 
    //发测版本额外显示一个分享按钮
    if (![DHAppConfig isDistributionVersion]) {
        self.navigationItem.lc_rightBarButtons = self.isShowShareButton ? @[_shareBtn, _testShareBtn] : @[_testShareBtn];
    }
 
    [self setNavgationLeftItem:NO];
}
 
- (void)onLeftNaviItemClick:(UIButton *)button
{
    if ([self.webView canGoBack] || self.isOpenPage) {
        //        [self.webView goBack];
        [super onLeftNaviItemClick:nil];
        if (self.isOpenPage) {
            WebOpenPageNum = WebOpenPageNum - 1;
        }
    } else {
        if (self.closeBlock) {
            self.closeBlock();
        }
 
        if (![NSString lc_isEmpty:_animationTypeStr]) {
            [DHAnimationManager animationType:_animationTypeStr directionType:kDirectionLeft onView:self.navigationController.view];
        }
 
        [self.navigationController popViewControllerAnimated:YES];
        if ([self.delegate respondsToSelector:@selector(dismissAdvertisementDetailViewController:)]) {
            [self.delegate dismissAdvertisementDetailViewController:self];
        }
    }
}
 
- (void)onRightShareBtnClick:(UIButton *)button
{
    if (self.shouldShowMore) {
        [self.bridge callHandler:@"noticeShowMore" data:nil responseCallback:^(id responseData) {
            NSLog(@"oc请求js - noticeShowMore 后接受的回调结果:%@", responseData);
        }];
    } else {
        //调用前端方法
 
        [DHAppStatistics eventWithEvent:advertisement_Share];
        LCSheetView *sheetView;
 
        sheetView = [[LCSheetView alloc]initWithTitle:nil message:nil delegate:self cancelButtonTitle:@"common_cancel".lc_T otherButtonTitles:@"common_tip_click_refresh".lc_T, nil];
 
        [sheetView buttonAtIndex:1].tag = ADVERSEMENT_REFRESH;
 
        [sheetView showAtView:self.view.window];
    }
}
 
- (void)setNavgationLeftItem:(BOOL)canGoBack
{
    if (canGoBack || self.isOpenPage) {
        //取消按钮
        UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
        //        closeButton.frame = CGRectMake(0, 0, 40, 40);
        [closeButton setImage:[UIImage imageNamed:@"common_image_nav_cancel"] forState:UIControlStateNormal];
        [closeButton setImage:[UIImage imageNamed:@"common_image_nav_cancel"] forState:UIControlStateHighlighted];
        [closeButton addTarget:self action:@selector(onCloseButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        self.navigationItem.lc_rightBarButtons = self.isShowShareButton ? @[closeButton, _shareBtn] : @[closeButton];
 
        //发测版本额外显示一个分享按钮
        if (![DHAppConfig isDistributionVersion]) {
            self.navigationItem.lc_rightBarButtons = self.isShowShareButton ? @[closeButton, _shareBtn, _testShareBtn, ] : @[closeButton, _testShareBtn];
        }
    } else {
        self.navigationItem.lc_rightBarButtons = self.isShowShareButton ? @[_shareBtn] : nil;
 
        //发测版本额外显示一个分享按钮
        if (![DHAppConfig isDistributionVersion]) {
            self.navigationItem.lc_rightBarButtons = self.isShowShareButton ? @[_shareBtn, _testShareBtn] : @[_testShareBtn];
        }
    }
}
 
//关闭整个webViewController
- (void)onCloseButtonClick:(UIButton *)btn
{
    if (self.closeBlock) {
        self.closeBlock();
    } else {
        //反序遍历导航栈
        NSArray<UIViewController *> *vcs = [[self.navigationController.viewControllers reverseObjectEnumerator] allObjects];
        UIViewController *pop2VC = nil;
        for (UIViewController *vc in vcs) {
            if ([vcs isMemberOfClass:[self class]]) {
                continue;
            } else {
                pop2VC = vc;
            }
        }
 
        if (pop2VC) {
            [self.navigationController popToViewController:pop2VC animated:YES];
        } else {
            [self.navigationController popToRootViewControllerAnimated:YES];
        }
    }
 
    WebOpenPageNum = 0;
 
    if (![NSString lc_isEmpty:_animationTypeStr]) {
        [DHAnimationManager animationType:_animationTypeStr directionType:kDirectionLeft onView:self.navigationController.view];
    }
 
    if ([self.delegate respondsToSelector:@selector(dismissAdvertisementDetailViewController:)]) {
        [self.delegate dismissAdvertisementDetailViewController:self];
    }
}
 
#pragma mark - H5 交互
- (void)handleDefenceSet:(NSDictionary *)cloudStateChangeDic
{
    NSDictionary *dict = [cloudStateChangeDic objectForKey:@"param"];
 
    NSMutableDictionary<NSString *, NSString *> *userInfo = [NSMutableDictionary dictionary];
    userInfo[@"deviceId"] = dict[@"deviceId"];
    userInfo[@"channelId"] = dict[@"channelId"];
 
    //不在线跳转到设备详情,在线跳转到防护配置
    id<IDHDeviceListManager> deviceManager = [DHModule implForService:@protocol(IDHDeviceListManager)];
    DHORMChannelObject *channelObject = [deviceManager getChannelWithDeviceId:dict[@"deviceId"] channelId:dict[@"channelId"]];
    if ([channelObject.status isEqualToString:@"online"]) {
        UIViewController *vc = [DHRouter objectForURL:@"/lechange/devicemanager/defenceset" withUserInfo:userInfo];
        [self.navigationController pushViewController:vc animated:YES];
    } else {
        UIViewController *vc = [DHRouter objectForURL:@"/lechange/devicemanager/deviceDetail" withUserInfo:userInfo];
        [self.navigationController pushViewController:vc animated:YES];
    }
}
 
- (void)handleApShareStateChange:(NSDictionary *)cloudStateChangeDic
{
}
 
- (void)handleDeviceShareStateChange:(NSDictionary *)cloudStateChangeDic
{
}
 
- (void)handleFriendApply:(NSDictionary *)cloudStateChangeDic {
}
 
- (void)handleAccountSafe:(NSDictionary *)cloudStateChangeDic {
}
 
- (void)handleAccountCancellation:(NSDictionary *)cloudStateChangeDic {
    //【*】国内使用H5进行注销,海外是native的; 清除用户登录信息
    if ([DHModuleConfig shareInstance].isLeChange) {
        [[NSNotificationCenter defaultCenter] postNotificationName:LCNotificationPasswordChange object:nil];
        [DHDataManager sharedInstance].username = nil;
    }
}
 
//点击通讯录查询按钮
- (void)handleShowContact
{
}
 
#pragma mark - DHAddressBookDelegate
- (void)selected:(NSString *)name phoneNumber:(NSString *)phoneNumber {
    NSString *purePhoneNumber = phoneNumber.dh_conversionPhoneNumber;
    //获取到手机通讯录联系人返回数据给h5
    NSDictionary *phoneDict = @{ @"phone": purePhoneNumber };
    NSMutableArray *resultArray = [[NSMutableArray alloc]initWithObjects:phoneDict, nil];
    [self callHandlerNoticeWebviewPhoneResult:resultArray];
}
 
- (void)selectPhoneNumbers:(NSArray *)phoneNumbers {
    NSMutableArray *resultArray = [[NSMutableArray alloc]init];
    for (int i = 0; i < phoneNumbers.count; i++) {
        NSString *purePhoneNumber = phoneNumbers[i];
        //获取到手机通讯录联系人返回数据给h5
        NSDictionary *phoneDict = @{ @"phone": purePhoneNumber.dh_conversionPhoneNumber };
        [resultArray addObject:phoneDict];
    }
    [self callHandlerNoticeWebviewPhoneResult:resultArray];
}
 
- (void)callHandlerNoticeWebviewPhoneResult:(NSMutableArray *)resultArray
{
    NSDictionary *dict = @{ @"result": resultArray };
    //回调数据给h5
    [self.bridge callHandler:@"noticeWebviewPhoneResult" data:dict.dh_jsonString responseCallback:^(id responseData) {
        NSLog(@"oc请求js后接受的回调结果:%@", responseData);
    }];
}
 
#pragma mark - MMSheetView Delegate
 
- (void)sheetView:(LCSheetView *)sheetView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    UIButton *btn = [sheetView buttonAtIndex:buttonIndex];
 
    if (btn.tag == ADVERSEMENT_REFRESH) {
        [self.webView reload];
    } else if (btn.tag == ADVERSEMENT_SHARE) {
    } else if (btn.tag == ADVERSEMENT_SAFARI) {
        if (self.webView.URL.absoluteString.length != 0) {
            [[UIApplication sharedApplication ] openURL:self.webView.URL];
        } else {
            [[UIApplication sharedApplication ] openURL:[NSURL URLWithString:self.playUrl]];
        }
    }
}
 
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
 
#ifdef LECHANGE
#pragma mark - Notifications
- (void)alipayCallBack:(NSNotification *)notification
{
    [self processWithAlipayResult:notification.object];
}
 
- (void)weixinPayCallBack:(NSNotification *)notification
{
    //[self.webView goBack];
    [super onLeftNaviItemClick:nil];
 
    //根据url网页获取标题
    [self.webView evaluateJavaScript:@"document.title"  completionHandler:^(NSString *response, NSError *_Nullable error) {
        if (response.length != 0) {
            self.title = response;
        }
    }];
}
 
- (void)sendLoginInfoToHtml:(NSNotification *)notification
{
    if (self.isAcceptNotificatin) {
        id<DHWebAuthLoginService> loginService = [DHModule implForService:@protocol(DHWebAuthLoginService)];
        NSString *matchUrl = [loginService getSignUrlWithSrcUrl:self.curUrl];
        matchUrl = matchUrl == nil ? self.curUrl : matchUrl;
        //直播和商城OC调用JS的方法  APP通知H5登录成功接口,入参免登录信息
        [self.bridge callHandler:@"getLoginInfo" data:[matchUrl lc_base64String] responseCallback:^(id responseData) {
            NSLog(@"oc请求js后接受的回调结果:%@", responseData);
        }];
 
        [self.bridge callHandler:@"noticeSignInResult" data:@{ @"result": @"true" }.dh_jsonString responseCallback:^(id responseData) {
            NSLog(@"oc请求js后接受的回调结果:%@", responseData);
        }];
    }
}
 
- (void)loginFailed:(NSNotification *)notification
{
    if (self.isAcceptNotificatin) {
        [self.bridge callHandler:@"noticeSignInResult" data:@{ @"result": @"false" }.dh_jsonString responseCallback:^(id responseData) {
            NSLog(@"oc请求js后接受的回调结果:%@", responseData);
        }];
    }
}
 
- (void)closeLogin:(NSNotification *)notification
{
    if (self.isAcceptNotificatin) {
        //直播和商城OC调用JS的方法  登录页面主动关闭,回传html地址给前端
        [self.bridge callHandler:@"getLoginInfo" data:[self.curUrl lc_base64String] responseCallback:^(id responseData) {
            NSLog(@"oc请求js后接受的回调结果:%@", responseData);
        }];
    }
}
 
/*
 9000——订单支付成功
 8000——正在处理中
 4000——订单支付失败
 5000——重复请求
 6001——用户中途取消
 6002——网络连接出错 */
- (void)processWithAlipayResult:(NSDictionary *)dicResult
{
    NSString *resultStatus =  [dicResult objectForKey:@"resultCode"];
    if ([resultStatus isEqualToString:@"9000"]) {
        NSString *returnUrl = dicResult[@"returnUrl"];
 
        if (returnUrl.length > 0) {
            //NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:returnUrl]];
            [self.webView goBack];
        }
    } else {
    }
}
 
- (void)onResume:(NSNotification *)notification {
    [self.bridge callHandler:@"noticeWebviewStatus" data:@{ @"status": @"onResume" }.dh_jsonString responseCallback:^(id responseData) {
        NSLog(@"oc请求js - noticeWebviewStatus 后接受的回调结果:%@", responseData);
    }];
}
 
- (void)addFriendResult:(NSNotification *)notification {
    [self.bridge callHandler:@"noticeAddFriendSuccess"];
}
 
- (void)addNewFriendNoti:(NSNotification *)notification {
    //h5刷新页面
    [self.bridge callHandler:@"noticeNewFriendAdd"];
}
 
- (void)resetViewData
{
    // 返回webView首层级并刷新下页面
    if ([self.webView canGoBack]) {
        WKBackForwardListItem *item = [[[self.webView backForwardList] backList] objectAtIndex:0];
        [self.webView goToBackForwardListItem:item];
    }
    [self.webView reload];
}
 
- (void)callBack:(NSString *)infoJson {
    [self.bridge callHandler:@"noticeAddContactResult" data:infoJson responseCallback:^(id responseData) {
    }];
}
 
#pragma mark - WKNavigationDelegate
- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
{
    [super webView:webView decidePolicyForNavigationAction:navigationAction decisionHandler:decisionHandler];
}
 
#endif
- (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation
{
    [super webView:webView didFinishNavigation:navigation];
 
    [self setNavgationLeftItem:webView.canGoBack];
}
 
- (id<IDHDeviceListManager>)listManager {
    return [DHModule implForService:@protocol(IDHDeviceListManager)];
}
 
#pragma mark - LCWebQRCodeScannerVCDelegate
 
- (void)scanResultWithText:(NSString *)text
{
//    noticeH5ScanResult//
    [self.bridge callHandler:@"noticeH5ScanResult" data:@{ @"result": text.lc_base64String }.dh_jsonString responseCallback:^(id responseData) {
    }];
}
 
#pragma mark - OpenPage 个数统计
//- (NSInteger)numOfOpenPage
 
#pragma mark - 日志搜集
- (void)openWebLog
{
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"log"];
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"error"];
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"warn"];
    [self.webView.configuration.userContentController addScriptMessageHandler:self name:@"info"];
 
    [self addJSScript];
 
    if (!_tap) {
        // 添加手势,触发进入LogVC
        _tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showLogVC)];
        [_tap setNumberOfTapsRequired:5];     // 设置当前需要点击的次数
        [_tap setNumberOfTouchesRequired:1];  // 设置当前需要触发事件的手指数量
        [self.navBar addGestureRecognizer:_tap];
    }
}
 
- (void)stopWebLog {
    //移除Handler
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"log"];
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"error"];
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"warn"];
    [self.webView.configuration.userContentController removeScriptMessageHandlerForName:@"info"];
    //移除JSScript
    [self.webView.configuration.userContentController removeAllUserScripts];
}
 
- (void)addJSScript
{
    // 重新console方法
    NSString *jsLogCode = @"console.log = (function(oriLogFunc){\
    return function(str)\
    {\
    window.webkit.messageHandlers.log.postMessage(str);\
    oriLogFunc.call(console,str);\
    }\
    })(console.log);";
 
    NSString *jsErrorCode = @"console.error = (function(oriLogFunc){\
    return function(str)\
    {\
    window.webkit.messageHandlers.error.postMessage(str);\
    oriLogFunc.call(console,str);\
    }\
    })(console.error);";
 
    NSString *jsWarnCode = @"console.warn = (function(oriLogFunc){\
    return function(str)\
    {\
    window.webkit.messageHandlers.warn.postMessage(str);\
    oriLogFunc.call(console,str);\
    }\
    })(console.warn);";
 
    NSString *jsInfoCode = @"console.info = (function(oriLogFunc){\
    return function(str)\
    {\
    window.webkit.messageHandlers.info.postMessage(str);\
    oriLogFunc.call(console,str);\
    }\
    })(console.info);";
 
    // 注入JS
    [self.webView.configuration.userContentController addUserScript:[[WKUserScript alloc] initWithSource:jsLogCode injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES]];
    [self.webView.configuration.userContentController addUserScript:[[WKUserScript alloc] initWithSource:jsErrorCode injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES]];
    [self.webView.configuration.userContentController addUserScript:[[WKUserScript alloc] initWithSource:jsWarnCode injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES]];
    [self.webView.configuration.userContentController addUserScript:[[WKUserScript alloc] initWithSource:jsInfoCode injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES]];
}
 
// JS回调
- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message
{
    // 目前前端打印的日志,只有字符串和数字
    NSString *str;
    if ([message.body isKindOfClass:[NSString class]]) {
        str = [message.body stringByReplacingOccurrencesOfString:@"\n" withString:@""];   // 会有多行字符串的打印,去掉换行符,否则过滤时会有问题
    } else if ([message.body isKindOfClass:[NSNumber class]]) {
        str = [NSString stringWithFormat:@"%@", message.body];
    }
    NSLog(@"【Web %@】 Source: %@  Content: %@", message.name, message.webView.URL, str);
}
 
// 跳转到查看日志的控制器
- (void)showLogVC
{
    LCWebLogViewController *logVC = [[LCWebLogViewController alloc]init];
    [self presentViewController:logVC animated:YES completion:nil];
}
 
@end