zoukankan      html  css  js  c++  java
  • iOS知识点总结

    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需要访问您的摄像头。
    请启用摄像头-设置/隐私/摄像头"];
                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需要访问您的麦克风。
    请启用麦克风-设置/隐私/麦克风"];
                        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;
            }
            
        }
  • 相关阅读:
    使用存储过程查询并按每页10条记录分页显示图书借阅纪录
    两个div并排 左边div宽固定 右边自适应
    java比较时间及时间的转换
    java使用commons.io的FileUtils进行文件拷贝
    实现image宽度100%,高度与宽度一致
    vue请求前的loading动画效果
    vue项目加载前空白的动画过渡效果
    element-ui和semantic-ui冲突的解决方法--局部引入semantic-ui的css
    vue使用formdata上传多个图片,springboot以文件数组的形式接受
    快速创建vuepress项目(使用vuepress写文档)
  • 原文地址:https://www.cnblogs.com/pengsi/p/7800077.html
Copyright © 2011-2022 走看看