標籤:init change 網路狀態 perm timer 學習 camera request frame
1.監測網路狀態:
- (void)checkNetwork { __block NSString *tips; _reachiabilityManager = [AFNetworkReachabilityManager manager]; [_reachiabilityManager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) { switch (status) { case -1:{ tips = @"未知網路錯誤"; break; } case 0:{ tips = @"暫無網路,請檢查網路"; break; } case 1:{ tips = @"當前串連的資料流量"; break; } case 2:{ tips = @"當前串連的是wifi"; break; } default: break; } if (tips.length) { // 提示 } }]; [_reachiabilityManager startMonitoring];}
2.進入直播頁面判斷許可權:
// 判斷是否是模擬器 if ([[UIDevice currentDevice] isSimulator]) { [self showNoticeMessage:@"請使用真機運行"]; return NO; } // 判斷是否有網路攝影機 if(![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){ [self showNoticeMessage:@"您的裝置沒有網路攝影機或者相關的驅動, 不能進行直播"]; return NO; } // 判斷是否有網路攝影機許可權 AVAuthorizationStatus authorizationStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; if (authorizationStatus == AVAuthorizationStatusRestricted|| authorizationStatus == AVAuthorizationStatusDenied) { [self showNoticeMessage:@"app需要訪問您的網路攝影機。\n請啟用網路攝影機-設定/隱私/網路攝影機"]; return NO; } // 開啟麥克風許可權 AVAudioSession *audioSession = [AVAudioSession sharedInstance]; if ([audioSession respondsToSelector:@selector(requestRecordPermission:)]) { [audioSession performSelector:@selector(requestRecordPermission:) withObject:^(BOOL granted) { if (granted) { return YES; } else { [self showNoticeMessage:@"app需要訪問您的麥克風。\n請啟用麥克風-設定/隱私/麥克風"]; return NO; } }]; }
3.直播使用的第三方:
視頻播放:IJKMediaFramework
彈幕:BarrageRenderer
推流:LFLiveKit
源碼學習: https://github.com/SunLiner/MiaowShow
4.Cell中的倒計時:
/// 每秒執行一次- (void)countDownWithPER_SECBlock:(void (^)())PER_SECBlock { if (_timer==nil) { dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue); dispatch_source_set_timer(_timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒執行 dispatch_source_set_event_handler(_timer, ^{ dispatch_async(dispatch_get_main_queue(), ^{ PER_SECBlock(); }); }); dispatch_resume(_timer); }}
5.搜尋時設定“搜尋高亮”:
// 設定搜尋高亮 if (model.searchKeyWord.length > 0) { // 從全部文字中找到特殊的文字 NSRange range = [model.titleStr rangeOfString:model.searchKeyWord]; if (range.location != NSNotFound && range.length > 0) { NSMutableAttributedString *muAttStr = [[NSMutableAttributedString alloc] initWithString:model.titleStr]; [muAttStr addAttribute:NSForegroundColorAttributeName value:BLUE_COLOR range:range]; self.titleLabel.attributedText = muAttStr; } }
iOS知識點總結