Commit b0fe2fd328554bdcb13a7f9420d80ee667ecf9a0

Authored by yinqiaojuan
1 parent 094e9a7c

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

CNLiveWitnessVideoModule.podspec
... ... @@ -8,7 +8,7 @@
8 8  
9 9 Pod::Spec.new do |s|
10 10 s.name = 'CNLiveWitnessVideoModule'
11   - s.version = '0.0.1'
  11 + s.version = '0.0.2'
12 12 s.summary = '目击者视频播放功能'
13 13  
14 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 45 @end
46 46  
47 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 55 - (instancetype)initControllerWithData:(NSDictionary *)data currentIndex:(NSInteger)currentIndex pageNum:(NSInteger)pageNum type:(NSString *)type {
49 56 if (self = [super init]) {
50 57 _dataSource = [NSMutableArray array];
51   - _currentPlayIndex = currentIndex;
52 58 _type = type;
53 59 _isHaveNext = @"1";
54 60 _pageIndex = pageNum + 1;
55 61 NSArray *list = data[@"witnessBeans"];
56 62 if ([type isEqualToString:@"0"]) {
57 63 _pageSize = 10;
  64 + _currentPlayIndex = currentIndex;
58 65 for (NSDictionary *dic in list) {
59 66 CNBWitnessListModel *witnessModel = [CNBWitnessListModel mj_objectWithKeyValues:dic];
60 67 [_dataSource addObject:witnessModel];
... ... @@ -63,6 +70,7 @@ NSString * const kIdentifier = @"CNBWitnessListCell";
63 70 NSDictionary *dic = list[currentIndex];
64 71 CNBWitnessListModel *witnessModel = [CNBWitnessListModel mj_objectWithKeyValues:dic];
65 72 [_dataSource addObject:witnessModel];
  73 + _currentPlayIndex = 0;
66 74 }
67 75  
68 76 }
... ... @@ -70,11 +78,20 @@ NSString * const kIdentifier = @"CNBWitnessListCell";
70 78 }
71 79 - (void)viewWillAppear:(BOOL)animated {
72 80 [super viewWillAppear:animated];
  81 + _isLightContentStatusBar = YES;
  82 + [self setNeedsStatusBarAppearanceUpdate];
  83 + [self monitorTheNetworkStatus];
73 84 self.navigationController.navigationBarHidden = YES;
74 85 }
75 86 - (void)viewDidDisappear:(BOOL)animated {
76 87 [super viewDidDisappear:animated];
77 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 96 - (void)viewDidLoad {
80 97 [super viewDidLoad];
... ... @@ -82,7 +99,7 @@ NSString * const kIdentifier = @"CNBWitnessListCell";
82 99 if ([self.type isEqualToString:@"0"]) {
83 100 self.toSid = ((CNBWitnessListModel *)[self.dataSource objectAtIndex:self.currentPlayIndex]).icon.sid;
84 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 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 209 - (void)loadWitnessData:(NSInteger)pageIndex{
142 210 __weak typeof(self) weakSelf = self;
143 211 [CNBWitnessListViewModel getWitnessListDataTosid:self.toSid page:self.pageIndex pageSize:self.pageSize successBlock:^(NSMutableArray * _Nonnull dataArray, NSString * _Nonnull isHaveNext) {
... ...