Commit b0fe2fd328554bdcb13a7f9420d80ee667ecf9a0

Authored by yinqiaojuan
1 parent 094e9a7c

添加网络监听和动态进来报错问题

CNLiveWitnessVideoModule.podspec
@@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
8 8
9 Pod::Spec.new do |s| 9 Pod::Spec.new do |s|
10 s.name = 'CNLiveWitnessVideoModule' 10 s.name = 'CNLiveWitnessVideoModule'
11 - s.version = '0.0.1' 11 + s.version = '0.0.2'
12 s.summary = '目击者视频播放功能' 12 s.summary = '目击者视频播放功能'
13 13
14 # This description is used to generate tags and improve search results. 14 # This description is used to generate tags and improve search results.
CNLiveWitnessVideoModule/Classes/Controller/CNBWitnessListController.m
@@ -45,16 +45,23 @@ NSString * const kIdentifier = @"CNBWitnessListCell"; @@ -45,16 +45,23 @@ NSString * const kIdentifier = @"CNBWitnessListCell";
45 @end 45 @end
46 46
47 @implementation CNBWitnessListController 47 @implementation CNBWitnessListController
  48 +- (void)dealloc {
  49 + NSLog(@"目击者播放页走了dealloc了吗");
  50 + [self.videoPlayerManager resetPlayer];
  51 + [[NSNotificationCenter defaultCenter]removeObserver:self];
  52 + _tableView.delegate = nil;
  53 + _tableView.dataSource = nil;
  54 +}
48 - (instancetype)initControllerWithData:(NSDictionary *)data currentIndex:(NSInteger)currentIndex pageNum:(NSInteger)pageNum type:(NSString *)type { 55 - (instancetype)initControllerWithData:(NSDictionary *)data currentIndex:(NSInteger)currentIndex pageNum:(NSInteger)pageNum type:(NSString *)type {
49 if (self = [super init]) { 56 if (self = [super init]) {
50 _dataSource = [NSMutableArray array]; 57 _dataSource = [NSMutableArray array];
51 - _currentPlayIndex = currentIndex;  
52 _type = type; 58 _type = type;
53 _isHaveNext = @"1"; 59 _isHaveNext = @"1";
54 _pageIndex = pageNum + 1; 60 _pageIndex = pageNum + 1;
55 NSArray *list = data[@"witnessBeans"]; 61 NSArray *list = data[@"witnessBeans"];
56 if ([type isEqualToString:@"0"]) { 62 if ([type isEqualToString:@"0"]) {
57 _pageSize = 10; 63 _pageSize = 10;
  64 + _currentPlayIndex = currentIndex;
58 for (NSDictionary *dic in list) { 65 for (NSDictionary *dic in list) {
59 CNBWitnessListModel *witnessModel = [CNBWitnessListModel mj_objectWithKeyValues:dic]; 66 CNBWitnessListModel *witnessModel = [CNBWitnessListModel mj_objectWithKeyValues:dic];
60 [_dataSource addObject:witnessModel]; 67 [_dataSource addObject:witnessModel];
@@ -63,6 +70,7 @@ NSString * const kIdentifier = @"CNBWitnessListCell"; @@ -63,6 +70,7 @@ NSString * const kIdentifier = @"CNBWitnessListCell";
63 NSDictionary *dic = list[currentIndex]; 70 NSDictionary *dic = list[currentIndex];
64 CNBWitnessListModel *witnessModel = [CNBWitnessListModel mj_objectWithKeyValues:dic]; 71 CNBWitnessListModel *witnessModel = [CNBWitnessListModel mj_objectWithKeyValues:dic];
65 [_dataSource addObject:witnessModel]; 72 [_dataSource addObject:witnessModel];
  73 + _currentPlayIndex = 0;
66 } 74 }
67 75
68 } 76 }
@@ -70,11 +78,20 @@ NSString * const kIdentifier = @"CNBWitnessListCell"; @@ -70,11 +78,20 @@ NSString * const kIdentifier = @"CNBWitnessListCell";
70 } 78 }
71 - (void)viewWillAppear:(BOOL)animated { 79 - (void)viewWillAppear:(BOOL)animated {
72 [super viewWillAppear:animated]; 80 [super viewWillAppear:animated];
  81 + _isLightContentStatusBar = YES;
  82 + [self setNeedsStatusBarAppearanceUpdate];
  83 + [self monitorTheNetworkStatus];
73 self.navigationController.navigationBarHidden = YES; 84 self.navigationController.navigationBarHidden = YES;
74 } 85 }
75 - (void)viewDidDisappear:(BOOL)animated { 86 - (void)viewDidDisappear:(BOOL)animated {
76 [super viewDidDisappear:animated]; 87 [super viewDidDisappear:animated];
77 self.navigationController.navigationBarHidden = NO; 88 self.navigationController.navigationBarHidden = NO;
  89 + _isLightContentStatusBar = NO;
  90 + [self setNeedsStatusBarAppearanceUpdate];
  91 + if ([self.videoPlayerManager rate] > 0) {
  92 + [self.videoPlayerManager autoPause];
  93 + }
  94 + [CNBWitnessListController removeNetworkStatue];
78 } 95 }
79 - (void)viewDidLoad { 96 - (void)viewDidLoad {
80 [super viewDidLoad]; 97 [super viewDidLoad];
@@ -82,7 +99,7 @@ NSString * const kIdentifier = @"CNBWitnessListCell"; @@ -82,7 +99,7 @@ NSString * const kIdentifier = @"CNBWitnessListCell";
82 if ([self.type isEqualToString:@"0"]) { 99 if ([self.type isEqualToString:@"0"]) {
83 self.toSid = ((CNBWitnessListModel *)[self.dataSource objectAtIndex:self.currentPlayIndex]).icon.sid; 100 self.toSid = ((CNBWitnessListModel *)[self.dataSource objectAtIndex:self.currentPlayIndex]).icon.sid;
84 }else { 101 }else {
85 - self.toSid = ((CNBWitnessListModel *)[self.dataSource objectAtIndex:self.currentPlayIndex]).contentSid; 102 + self.toSid = ((CNBWitnessListModel *)self.dataSource[self.currentPlayIndex]).contentSid;
86 } 103 }
87 104
88 } 105 }
@@ -138,6 +155,57 @@ NSString * const kIdentifier = @"CNBWitnessListCell"; @@ -138,6 +155,57 @@ NSString * const kIdentifier = @"CNBWitnessListCell";
138 return UIStatusBarStyleDefault; 155 return UIStatusBarStyleDefault;
139 } 156 }
140 } 157 }
  158 +#pragma mark - 网络监听
  159 +- (void)monitorTheNetworkStatus {
  160 + __weak typeof(self) weakSelf = self;
  161 + [CNBWitnessListController networkStatusWithBlock:^(CNLiveNetworkStatusType status) {
  162 + switch (status) {
  163 + case CNLiveNetworkStatusNotReachable:{
  164 + [weakSelf.videoPlayerManager autoPause];
  165 + }
  166 + break;
  167 + case CNLiveNetworkStatusUnknown:{
  168 + [weakSelf.videoPlayerManager autoPause];
  169 + }
  170 + break;
  171 + case CNLiveNetworkStatusReachableViaWiFi:{
  172 + NSLog(@"现在是wifi");
  173 + }
  174 + break;
  175 + case CNLiveNetworkStatusReachableViaWWAN:{
  176 + BOOL isAgress4G = [[NSUserDefaults standardUserDefaults] objectForKey: @"isAgress4G"];
  177 + if (!isAgress4G) {
  178 + [weakSelf.videoPlayerManager autoPause];
  179 + [weakSelf showVideoAlertView];
  180 + }else {
  181 + BOOL is4G = [[NSUserDefaults standardUserDefaults]objectForKey:@"is4G"];
  182 + if (!is4G) {
  183 + [QMUITips showWithText:@"当前为非WiFi环境,请注意流量消耗" inView:CNBWitnessAppKeyWindow hideAfterDelay:1.0f];
  184 + [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"isAgress4G" ]; //是否是4G
  185 + }
  186 + }
  187 + }
  188 + break;
  189 + default:
  190 + break;
  191 + }
  192 + }];
  193 +}
  194 +#pragma mark - 是否允许4G
  195 +- (void)showVideoAlertView {
  196 + __weak typeof(self) weakSelf = self;
  197 + UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"当前为非Wifi环境,已为您暂停播放" message:nil preferredStyle:UIAlertControllerStyleAlert];
  198 + UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"继续播放" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  199 +// [CNWitnessAVPlayerManager shareManager].isAgress4G = YES;
  200 + [weakSelf.videoPlayerManager play];
  201 + //将同意4G存起来状态保存起来
  202 + [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"isAgress4G" ];
  203 +
  204 + }];
  205 + [alertController addAction:action1];
  206 + [self presentViewController:alertController animated:YES completion:nil];
  207 +}
  208 +#pragma mark - 加载数据
141 - (void)loadWitnessData:(NSInteger)pageIndex{ 209 - (void)loadWitnessData:(NSInteger)pageIndex{
142 __weak typeof(self) weakSelf = self; 210 __weak typeof(self) weakSelf = self;
143 [CNBWitnessListViewModel getWitnessListDataTosid:self.toSid page:self.pageIndex pageSize:self.pageSize successBlock:^(NSMutableArray * _Nonnull dataArray, NSString * _Nonnull isHaveNext) { 211 [CNBWitnessListViewModel getWitnessListDataTosid:self.toSid page:self.pageIndex pageSize:self.pageSize successBlock:^(NSMutableArray * _Nonnull dataArray, NSString * _Nonnull isHaveNext) {