iOS知識點總結

來源:互聯網
上載者:User

標籤: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知識點總結

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.