// // XYLiveManger.m // Starbuds // // Created by pajia on 2019/12/31. // Copyright © 2019 翟玉磊. All rights reserved. // #import "XYLiveManger.h" #import "XYLiveRoomAPIManager.h" #import "NSString+Utility.h" #import "XYShortVideoController.h" #import "XYExpressionItemView.h" #import "XYNiceNumView.h" static XYLiveManger *_sharedInstance; @interface XYLiveManger(){ } @property (nonatomic, strong) NSString *whitenValue; //美白 @property (nonatomic, strong) NSString *smoothValue; //磨皮 @property (nonatomic, strong) NSString *redRosyValue; //红润 @property (nonatomic, strong) NSString *highLightValue; //去高光 @property (nonatomic, strong) NSString *faceLiftValue; //瘦脸 @property (nonatomic, strong) NSString *enlargeEyeValue; //大眼 @property (nonatomic, strong) NSString *smallFaceValue; //小脸 @property (nonatomic, strong) NSString *faceOverallValue; //窄脸 @property (nonatomic, strong) NSString *roundEyesValue; //圆眼 @property (nonatomic, strong) NSString *jawValue; //下巴 @property (nonatomic, strong) NSString *foreheadValue; //额头 @property (nonatomic, strong) NSString *appleMuscleValue; //苹果肌 @property (nonatomic, strong) NSString *thinNoseValue; //瘦鼻翼 @property (nonatomic, strong) NSString *proboscidesValue; //长鼻 @property (nonatomic, strong) UILabel *titlelab; @property (nonatomic, strong) NSTimer *keepBrightScreenTimer; @end @implementation XYLiveManger +(XYLiveManger *)shareInstance{ @synchronized(self){ if (_sharedInstance == nil){ _sharedInstance = [[self alloc] init]; } } return _sharedInstance; } - (instancetype)init{ if (self = [super init]) { _whitenValue = @"0.5"; //美白 _smoothValue = @"0.65"; //磨皮 _redRosyValue = @"0.5"; //红润 _highLightValue = @"0.0"; //去高光0.5 _faceLiftValue = @"0.5"; //瘦脸 _enlargeEyeValue = @"0.0"; //大眼 _smallFaceValue = @"0.0"; //小脸 _faceOverallValue = @"0.0"; //窄脸 _roundEyesValue = @"0.0"; //圆眼 _jawValue = @"0.0"; //下巴 _foreheadValue = @"0.0"; //额头 _appleMuscleValue = @"0.0"; //苹果肌 _thinNoseValue = @"0.0"; //瘦鼻翼 _proboscidesValue = @"0.0"; //长鼻 NSDictionary *dict = [[NSUserDefaults standardUserDefaults] objectForKey:@"saveBeautyDefaultValue"]; if (dict[@"whitenValue"]) { _whitenValue = dict[@"whitenValue"]; } if (dict[@"smoothValue"]) { _smoothValue = dict[@"smoothValue"]; } if (dict[@"redRosyValue"]) { _redRosyValue = dict[@"redRosyValue"]; } if (dict[@"highLightValue"]) { _highLightValue = dict[@"highLightValue"]; } if (dict[@"faceLiftValue"]) { _faceLiftValue = dict[@"faceLiftValue"]; } if (dict[@"enlargeEyeValue"]) { _enlargeEyeValue = dict[@"enlargeEyeValue"]; } if (dict[@"smallFaceValue"]) { _smallFaceValue = dict[@"smallFaceValue"]; } if (dict[@"faceOverallValue"]) { _faceOverallValue = dict[@"faceOverallValue"]; } if (dict[@"roundEyesValue"]) { _roundEyesValue = dict[@"roundEyesValue"]; } if (dict[@"jawValue"]) { _jawValue = dict[@"jawValue"]; } if (dict[@"foreheadValue"]) { _foreheadValue = dict[@"foreheadValue"]; } if (dict[@"appleMuscleValue"]) { _appleMuscleValue = dict[@"appleMuscleValue"]; } if (dict[@"thinNoseValue"]) { _thinNoseValue = dict[@"thinNoseValue"]; } if (dict[@"proboscidesValue"]) { _proboscidesValue = dict[@"proboscidesValue"]; } _currentFilterName = kLocalizedString(@"正常"); NSDictionary *dict1 = [[NSUserDefaults standardUserDefaults] objectForKey:@"saveFilterDefault"]; if (dict1[@"currentFilterName"]) { _currentFilterName = dict1[@"currentFilterName"]; } if (dict1[@"currentFilterPath"]) { _currentFilterPath = dict1[@"currentFilterPath"]; } if (dict1[@"currentFilterValue"]) { _currentFilterValue = dict1[@"currentFilterValue"]; } if ([[NSUserDefaults standardUserDefaults] objectForKey:@"HDWindowLoggerShow"]) { _HDWindowLoggerShow = YES; } } return self; } - (NSString *)stringFromTxtFile:(NSString *)path{ NSData *data = [NSData dataWithContentsOfFile:path]; NSMutableString *content = [[NSMutableString alloc] initWithData:data encoding:NSUTF8StringEncoding]; return content; } - (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString { if (jsonString == nil) { return nil; } NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding]; NSError *err; NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err]; if(err){ return nil; } return dic; } -(NSString*)dictionaryToJson:(NSDictionary *)dic{ NSError *parseError = nil; NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&parseError]; return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; } - (UIImage *)convertViewToImage:(UIView *)view { view.backgroundColor = [UIColor clearColor]; UIImage *imageRet = [[UIImage alloc] init]; UIGraphicsBeginImageContextWithOptions(view.frame.size, NO, [UIScreen mainScreen].scale); [view.layer renderInContext:UIGraphicsGetCurrentContext()]; imageRet = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return imageRet; } #pragma mark - liveroomlogic #pragma mark chatlist ///房间聊天列表、个人详情,设置用户标签(等级等),richText后面追加内容(名字lable) - (void)setUserMarks:(XYLiveRoomMessageInfo *)info andRichText:(AWRichText *)richText{ XYUserMarkIconInfo *markInfo = [[XYUserMarkIconInfo alloc] init]; //新人标签 if (info.userInfo.isNew) { markInfo.isNewMan = YES; } //官方标签 if ([info.userRole integerValue] == XYVoiceRoomRoleOfficial) { markInfo.isOfficial = YES; } //主持人 if ([info.userRole integerValue] == XYVoiceRoomRoleHost) { markInfo.isHost = YES; } //房管 if ([info.userRole integerValue] == XYVoiceRoomRoleMaster) { markInfo.isManager = YES; } //房主 if ([info.userRole integerValue] == XYVoiceRoomRoleAdmin) { markInfo.isHouseOwer = YES; } //超管(直播时用的) if ([info.userRole integerValue] == XYVoiceRoomRoleSuper) { markInfo.isSuperManager = YES; } //勋章 if (info.medalId.length > 0) { markInfo.medalId = info.medalId; } //用户等级 if (info.grageNum > 0) { markInfo.wealthLevel = info.grageNum; markInfo.wealthMedalStatus = info.grageMedalStatus; } //语音等级 if ([info.starLevel integerValue] > 0) { markInfo.starLevel = [info.starLevel integerValue]; } //靓号 if ([info.niceNo integerValue] > 0 && info.niceLevel> 0) { markInfo.niceNo = info.niceNo; markInfo.niceLevel = info.niceLevel; } //性别 if (info.userSex) { markInfo.sex = info.userSex; markInfo.age = [info.userAge integerValue]; } //贵族标签 if ([info.nobleValue integerValue] > 0) { markInfo.nobleLevel = [info.nobleValue integerValue];; } //vip标签 if ([info.vipValue integerValue] > 0) { markInfo.vipValue = [info.vipValue integerValue]; } //勋章 if (info.activityMedals.count > 0) { markInfo.activityMedals = info.activityMedals; } XYUserMarkIconView *markView = [[XYUserMarkIconView alloc] init]; [markView reload:markInfo andRichText:richText]; } #pragma mark barrage - (UIImage *)getGradeNumImage:(XYLiveRoomMessageInfo *)info{ // UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 20)]; // view.backgroundColor = [UIColor clearColor]; // // UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 20)]; // imgView.contentMode = UIViewContentModeScaleAspectFill; // imgView.image = [UIImage imageNamed:[self getGradeImg:info]]; // [view addSubview:imgView]; // // UILabel *lab = [[UILabel alloc]init]; // lab.font = [UIFont fontWithName:kPFSCMediumFont size:12]; // lab.textColor = [UIColor colorWithHexString:@"#FFFFFF" alpha:1]; // lab.textAlignment = NSTextAlignmentRight; // lab.text = [NSString stringWithFormat:@"%ld",(long)info.grageNum]; // lab.frame = CGRectMake(0, 0, 34, 20); // [view addSubview:lab]; // // UIImage *gradeImg = [self convertViewToImage:view]; // return gradeImg; UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 48, 20)]; view.backgroundColor = [UIColor clearColor]; UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 48, 20)]; imgView.contentMode = UIViewContentModeScaleAspectFill; imgView.image = [UIImage imageNamed:[self getGradeImg:info]]; [view addSubview:imgView]; UIImage *gradeImg = [self convertViewToImage:view]; return gradeImg; } - (NSString *)getGradeImg:(XYLiveRoomMessageInfo *)info{ // if (info.grageNum <= 10) { // return @"xy-icon-grade1"; // // }else if (info.grageNum >= 11 && info.grageNum <= 20){ // return @"xy-icon-grade2"; // // }else if (info.grageNum >= 21 && info.grageNum <= 30){ // return @"xy-icon-grade3"; // // }else if (info.grageNum >= 31 && info.grageNum <= 40){ // return @"xy-icon-grade4"; // // }else if (info.grageNum >= 51 && info.grageNum <= 50){ // return @"xy-icon-grade5"; // // } // return @"xy-icon-grade5"; NSString *imgname = [NSString stringWithFormat:@"X_LV_%ld",info.grageNum]; return imgname; } - (UIImage *)getAnchorGradeNumImage:(XYLiveRoomMessageInfo *)info{ UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 20)]; view.backgroundColor = [UIColor clearColor]; UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 20)]; imgView.contentMode = UIViewContentModeScaleAspectFill; imgView.image = [UIImage imageNamed:[self getAnchorGradeImg:info]]; [view addSubview:imgView]; UILabel *lab = [[UILabel alloc]init]; lab.font = [UIFont fontWithName:kPFSCMediumFont size:12]; lab.textColor = [UIColor colorWithHexString:@"#FFFFFF" alpha:1]; lab.textAlignment = NSTextAlignmentRight; lab.text = [NSString stringWithFormat:@"%ld",(long)info.anchorGrageNum]; lab.frame = CGRectMake(0, 0, 34, 20); [view addSubview:lab]; UIImage *gradeImg = [self convertViewToImage:view]; return gradeImg; } - (NSString *)getAnchorGradeImg:(XYLiveRoomMessageInfo *)info{ if (info.anchorGrageNum <= 10) { return @"xy-icon-anchorgrade1"; }else if (info.anchorGrageNum >= 11 && info.anchorGrageNum <= 20){ return @"xy-icon-anchorgrade2"; }else if (info.anchorGrageNum >= 21 && info.anchorGrageNum <= 30){ return @"xy-icon-anchorgrade3"; }else if (info.anchorGrageNum >= 31 && info.anchorGrageNum <= 40){ return @"xy-icon-anchorgrade4"; }else if (info.anchorGrageNum >= 51 && info.anchorGrageNum <= 50){ return @"xy-icon-anchorgrade5"; } return @"xy-icon-anchorgrade1"; } - (UIImage *)getVoiceRoomLevelImage:(XYLiveRoomMessageInfo *)info{ UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 20)]; view.backgroundColor = [UIColor clearColor]; UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 20)]; imgView.contentMode = UIViewContentModeScaleAspectFill; imgView.image = [UIImage imageNamed:[self getVoiceRoomLevelImg:info]]; [view addSubview:imgView]; UILabel *lab = [[UILabel alloc]init]; lab.font = [UIFont fontWithName:kPFSCMediumFont size:12]; lab.textColor = [UIColor colorWithHexString:@"#FFFFFF" alpha:1]; lab.textAlignment = NSTextAlignmentRight; lab.text = [NSString stringWithFormat:@"%@",info.starLevel]; lab.frame = CGRectMake(0, 0, 34, 20); [view addSubview:lab]; UIImage *gradeImg = [self convertViewToImage:view]; return gradeImg; } - (NSString *)getVoiceRoomLevelImg:(XYLiveRoomMessageInfo *)info{ if ([info.starLevel integerValue] <= 10) { return @"xy-icon-voiceroom-tag1~10"; }else if ([info.starLevel integerValue] >= 11 && [info.starLevel integerValue] <= 20){ return @"xy-icon-voiceroom-tag11~20"; }else if ([info.starLevel integerValue] >= 21 && [info.starLevel integerValue] <= 30){ return @"xy-icon-voiceroom-tag21~30"; }else if ([info.starLevel integerValue] >= 31 && [info.starLevel integerValue]<= 40){ return @"xy-icon-voiceroom-tag31~40"; }else if ([info.starLevel integerValue] >= 51 && [info.starLevel integerValue]<= 50){ return @"xy-icon-voiceroom-tag41~50"; } return @"xy-icon-voiceroom-tag1~10"; } - (UIImage *)getFansNameImage{ UIView *view = [[UIView alloc] init]; view.backgroundColor = [UIColor clearColor]; UIImageView *imgView = [[UIImageView alloc] init]; [view addSubview:imgView]; UILabel *lab = [[UILabel alloc] init]; lab.font = [UIFont fontWithName:kPFSCMediumFont size:10]; lab.textColor = [UIColor colorWithHexString:@"#FFFFFF" alpha:1]; lab.textAlignment = NSTextAlignmentRight; lab.text = self.currentRoomFansName; [view addSubview:lab]; float fansNameStrWidth = [lab.text stringWidth:lab.font andHeight:20]; lab.frame = CGRectMake(18, 0, fansNameStrWidth, 20); fansNameStrWidth = fansNameStrWidth + 4; UIImage *image = [UIImage imageNamed:@"xy-icon-userfans"]; image = [image stretchableImageWithLeftCapWidth:image.size.width * 0.5 topCapHeight:image.size.height * 0.5]; imgView.image = image; imgView.frame = CGRectMake(0, 0, fansNameStrWidth + 20, 20); view.frame = CGRectMake(0, 0, fansNameStrWidth + 20, 20); UIImage *gradeImg = [self convertViewToImage:view]; return gradeImg; } - (UIImage *)getNiceNoImage:(XYLiveRoomMessageInfo *)info{ UIView *view = [[UIView alloc] init]; view.backgroundColor = [UIColor clearColor]; UIImageView *imgView = [[UIImageView alloc] init]; [view addSubview:imgView]; UILabel *lab = [[UILabel alloc] init]; lab.font = [UIFont fontWithName:kPFSCMediumFont size:10]; lab.textColor = [UIColor colorWithHexString:@"#2A1824" alpha:1]; lab.textAlignment = NSTextAlignmentRight; lab.text = [NSString stringWithFormat:@"%@",info.niceNo]; [view addSubview:lab]; float labTextWidth = [lab.text stringWidth:lab.font andHeight:14]; lab.frame = CGRectMake(4, 0, labTextWidth, 20); UIImage *image = [UIImage imageNamed:@"xy-lr-icon-niceshadow"]; image = [image stretchableImageWithLeftCapWidth:image.size.width * 0.5 topCapHeight:image.size.height * 0.5]; imgView.image = image; imgView.frame = CGRectMake(0, 0, labTextWidth + 8, 20); view.frame = CGRectMake(0, 0, labTextWidth + 8, 20); UIImage *niceNoImage = [self convertViewToImage:view]; return niceNoImage; } - (UIView *)getSexView:(XYLiveRoomMessageInfo *)info{ UIView *view = [[UIView alloc] init]; if (info.userSex == 1) { view.backgroundColor = [UIColor colorWithHexString:@"#79E5FF" alpha:1]; UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)]; imgView.image = [UIImage imageNamed:@"xy-icon-userboy"]; [view addSubview:imgView]; } if (info.userSex == 2) { view.backgroundColor = [UIColor colorWithHexString:@"#FD7A8F" alpha:1]; UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)]; imgView.image = [UIImage imageNamed:@"xy-icon-usergirl"]; [view addSubview:imgView]; } if ([info.userAge integerValue] > 0) { view.frame = CGRectMake(0, 0, 36, 20); UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, view.width-4, view.height)]; lab.text = info.userAge; lab.textAlignment = NSTextAlignmentRight; lab.font = [UIFont fontWithName:kPFSCMediumFont size:12]; lab.textColor = [UIColor whiteColor]; [view addSubview:lab]; }else{ view.frame = CGRectMake(0, 0, 20, 20); } kViewRadius(view, 4); return view; } - (void)stopAnchorLiveRoom{ NSString *liveHisId = [[NSUserDefaults standardUserDefaults] objectForKey:@"liveHisId"]; if (liveHisId.length) { NSMutableDictionary *param = [[NSMutableDictionary alloc] init]; [param setObject:liveHisId forKey:@"liveHisId"]; [[XYLiveRoomAPIManager new] liveStopLive:param successHandler:^(ZYLResponseModel *responseModel) { [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"liveHisId"]; } failureHandler:^(ZYLNetworkError *error) { }]; } } //礼物界面用户分数等级值 - (void)requestGiftListUserScoreData{ if ([XYUserInfoManager nowUser]) { NSMutableDictionary *param = [[NSMutableDictionary alloc] init]; [param setObject:@"11" forKey:@"scoreType"]; [[XYLiveRoomAPIManager new] getScoreLevelInfo:param successHandler:^(ZYLResponseModel *responseModel) { [XYLiveManger shareInstance].scoreLevelInfoDataDict = responseModel.data; } failureHandler:^(ZYLNetworkError *error) { }]; } } - (void)beautyEffectViewClear{ } - (void)saveBeautyDefaultValue{ NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; [dict setObject:self.whitenValue forKey:@"whitenValue"]; [dict setObject:self.smoothValue forKey:@"smoothValue"]; [dict setObject:self.redRosyValue forKey:@"redRosyValue"]; [dict setObject:self.highLightValue forKey:@"highLightValue"]; [dict setObject:self.faceLiftValue forKey:@"faceLiftValue"]; [dict setObject:self.enlargeEyeValue forKey:@"enlargeEyeValue"]; [dict setObject:self.smallFaceValue forKey:@"smallFaceValue"]; [dict setObject:self.faceOverallValue forKey:@"faceOverallValue"]; [dict setObject:self.roundEyesValue forKey:@"roundEyesValue"]; [dict setObject:self.jawValue forKey:@"jawValue"]; [dict setObject:self.foreheadValue forKey:@"foreheadValue"]; [dict setObject:self.appleMuscleValue forKey:@"appleMuscleValue"]; [dict setObject:self.thinNoseValue forKey:@"thinNoseValue"]; [dict setObject:self.proboscidesValue forKey:@"proboscidesValue"]; [[NSUserDefaults standardUserDefaults] setObject:dict forKey:@"saveBeautyDefaultValue"]; } - (void )setBeautyDefaultValue:(LiveRoomBeautyType )type andValue:(NSString *)value{ } - (NSString *)getBeautyDefaultValue:(LiveRoomBeautyType )type{ if (type == LiveRoomBeautyTypeWhiten){ return self.whitenValue; }else if (type == LiveRoomBeautyTypeSmooth){ return self.smoothValue; }else if (type == LiveRoomBeautyTypeRedRosy){ return self.redRosyValue; }else if (type == LiveRoomBeautyTypeHighLight){ return self.highLightValue; }else if (type == LiveRoomBeautyTypeFaceLift){ return self.faceLiftValue; }else if (type == LiveRoomBeautyTypeEnlargeEye){ return self.enlargeEyeValue; }else if (type == LiveRoomBeautyTypeSmallFace){ return self.smallFaceValue; }else if (type == LiveRoomBeautyTypeFaceOverall){ return self.faceOverallValue; }else if (type == LiveRoomBeautyTypeRoundEyes){ return self.roundEyesValue; }else if (type == LiveRoomBeautyTypeJaw){ return self.jawValue; }else if (type == LiveRoomBeautyTypeForehead){ return self.foreheadValue; }else if (type == LiveRoomBeautyTypeAppleMuscle){ return self.appleMuscleValue; }else if (type == LiveRoomBeautyTypeThinNose){ return self.thinNoseValue; }else if (type == LiveRoomBeautyTypeProboscides){ return self.proboscidesValue; } return nil; } - (void)saveFilterDefault{ NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; [dict setObject:self.currentFilterPath forKey:@"currentFilterPath"]; [dict setObject:self.currentFilterValue forKey:@"currentFilterValue"]; [dict setObject:self.currentFilterName forKey:@"currentFilterName"]; [[NSUserDefaults standardUserDefaults] setObject:dict forKey:@"saveFilterDefault"]; } - (void)setFilterDefault{ NSDictionary *dict = [[NSUserDefaults standardUserDefaults] objectForKey:@"saveFilterDefault"]; self.currentFilterPath = dict[@"currentFilterPath"]; self.currentFilterValue = dict[@"currentFilterValue"]; self.currentFilterName = dict[@"currentFilterName"]; if (!self.currentFilterName.length) { self.currentFilterName = kLocalizedString(@"正常"); } } - (void)setFilterDefaultPath:(NSString *)path andValue:(NSString *)value{ self.currentFilterPath = path; self.currentFilterValue = value; } - (NSString *)getFilterDefaultPath:(LiveRoomBeautyType )type{ return self.currentFilterPath; } - (NSString *)getFilterDefaultValue:(LiveRoomBeautyType )type{ return self.currentFilterPath; } - (NSString *)caluteWValue:(NSInteger )a{ NSString *value; NSInteger b = a / 10000; if (b < 1) { value = [NSString stringWithFormat:@"%ld",(long)a]; return value; } NSInteger c = a % 10000; NSInteger d = c / 1000; value = [NSString stringWithFormat:@"%ld.%ldW",(long)b,(long)d]; return value; } - (CGSize )getABstringSize:(NSAttributedString *)abString{ self.titlelab.attributedText = abString; [self.titlelab sizeToFit]; //CGRect frame = self.titlelab.frame; return self.titlelab.size; } - (UILabel *)titlelab{ if (_titlelab == nil) { _titlelab = [[UILabel alloc] init]; _titlelab.text = @""; _titlelab.textAlignment = NSTextAlignmentLeft; _titlelab.textColor = [UIColor colorWithHexString:@"#FFFFFF" alpha:1]; _titlelab.font = [UIFont fontWithName:kPFSCMediumFont size:16]; [_titlelab sizeToFit]; //_titlelab.hidden = YES; //[[UIApplication sharedApplication].keyWindow addSubview:_titlelab]; } return _titlelab; } - (void)judgeCameraMic{ kWEAKSELF NSString *mediaType = AVMediaTypeVideo;// Or AVMediaTypeAudio AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType]; if (authStatus == AVAuthorizationStatusAuthorized) { AVAudioSession *avSession = [AVAudioSession sharedInstance]; if ([avSession respondsToSelector:@selector(requestRecordPermission:)]) { [avSession requestRecordPermission:^(BOOL available) { if (available) { //completionHandler dispatch_async(dispatch_get_main_queue(), ^{ if (weakSelf.AppCameraMicBlock) { weakSelf.AppCameraMicBlock(YES); } }); }else{ dispatch_async(dispatch_get_main_queue(), ^{ NSString *content = [NSString stringWithFormat:kLocalizedString(@"请在“设置-隐私-麦克风”选项中允许‘%@’访问你的麦克风"), APP_NAME]; CustomActionAlertController *al = [[CustomActionAlertController alloc] initWithTitle:[NSString stringWithFormat:@"%@%@",APP_NAME, kLocalizedString(@"想访问您的麦克风")] message:content sure:kLocalizedString(@"设置") cancel:kLocalizedString(@"取消") selctedBlock:^(NSInteger index, NSString * _Nonnull title){ if ([title isEqualToString:kLocalizedString(@"设置")]) { [weakSelf intoSystemSet]; } }]; [al show]; }); } }]; } }else if(authStatus == AVAuthorizationStatusNotDetermined){ // Explicit user permission is required for media capture, but the user has not yet granted or denied such permission. [AVCaptureDevice requestAccessForMediaType:mediaType completionHandler:^(BOOL granted) { if(granted){//点击允许访问时调用 //用户明确许可与否,媒体需要捕获,但用户尚未授予或拒绝许可。 AVAudioSession *avSession = [AVAudioSession sharedInstance]; if ([avSession respondsToSelector:@selector(requestRecordPermission:)]) { [avSession requestRecordPermission:^(BOOL available) { if (available) { //completionHandler dispatch_async(dispatch_get_main_queue(), ^{ if (weakSelf.AppCameraMicBlock) { weakSelf.AppCameraMicBlock(YES); } }); }else{ dispatch_async(dispatch_get_main_queue(), ^{ NSString *content = [NSString stringWithFormat:kLocalizedString(@"请在“设置-隐私-麦克风”选项中允许‘%@’访问你的麦克风"), APP_NAME]; CustomActionAlertController *al = [[CustomActionAlertController alloc] initWithTitle:[NSString stringWithFormat:@"%@%@",APP_NAME, kLocalizedString(@"想访问您的麦克风")] message:content sure:kLocalizedString(@"设置") cancel:kLocalizedString(@"取消") selctedBlock:^(NSInteger index, NSString * _Nonnull title){ if ([title isEqualToString:kLocalizedString(@"设置")]) { [weakSelf intoSystemSet]; } }]; [al show]; }); } }]; } }else { dispatch_async(dispatch_get_main_queue(), ^{ NSString *content = [NSString stringWithFormat:kLocalizedString(@"请在“设置-隐私-麦克风”选项中允许‘%@’访问你的麦克风"), APP_NAME]; CustomActionAlertController *al = [[CustomActionAlertController alloc] initWithTitle:[NSString stringWithFormat:@"%@%@",APP_NAME, kLocalizedString(@"想访问您的麦克风")] message:content sure:kLocalizedString(@"设置") cancel:kLocalizedString(@"取消") selctedBlock:^(NSInteger index, NSString * _Nonnull title){ if ([title isEqualToString:kLocalizedString(@"设置")]) { [weakSelf intoSystemSet]; } }]; [al show]; }); } }]; }else{ dispatch_async(dispatch_get_main_queue(), ^{ NSString *content = [NSString stringWithFormat:kLocalizedString(@"请在“设置-隐私-麦克风”选项中允许‘%@’访问你的麦克风"), APP_NAME]; CustomActionAlertController *al = [[CustomActionAlertController alloc] initWithTitle:[NSString stringWithFormat:@"%@%@",APP_NAME, kLocalizedString(@"想访问您的麦克风")] message:content sure:kLocalizedString(@"设置") cancel:kLocalizedString(@"取消") selctedBlock:^(NSInteger index, NSString * _Nonnull title){ if ([title isEqualToString:kLocalizedString(@"设置")]) { [weakSelf intoSystemSet]; } }]; [al show]; }); } } - (void)intoSystemSet{ NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString]; [[UIApplication sharedApplication] openURL:url]; } - (void)intoSystemAvdioSet{ NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString]; [[UIApplication sharedApplication] openURL:url]; } - (void)keepBrightScreen{ if (!self.keepBrightScreenTimer) { self.keepBrightScreenTimer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(keepBrightScreenTimerAction) userInfo:nil repeats:YES]; [UIApplication sharedApplication].idleTimerDisabled = YES; } } - (void)keepBrightScreenTimerAction{ [UIApplication sharedApplication].idleTimerDisabled = YES; } - (void)cancelKeepBrightScreen{ [self.keepBrightScreenTimer invalidate]; self.keepBrightScreenTimer = nil; [UIApplication sharedApplication].idleTimerDisabled = NO; } - (void)pushLiveRoom:(NSString *)userid extra:(XYLiveRoomVCInfo *)extraInfo{ } - (void)removeControllerWithClass:(Class)newClass { //删除指定栈内的控制器 NSMutableArray *marr = [[NSMutableArray alloc]initWithArray:[AppDelegate sharedDelegate].getCurrentController.navigationController.viewControllers]; for (NSInteger i = 0; i < marr.count; i++) { UIViewController *vc = marr[i]; //防止删掉当前控制器 if (i != (marr.count-1)) { if ([vc isKindOfClass:newClass]) { [marr removeObject:vc]; break; } } } [AppDelegate sharedDelegate].getCurrentController.navigationController.viewControllers = marr; /* Removes the the receiver from its parent's children controllers array. If this method is overridden then the super implementation must be called. */ // [self removeFromParentViewController]; } - (UIView *)getSvgaView:(XYLiveRoomMessageInfo *)info{ XYExpressionItemView *view = [[XYExpressionItemView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)]; [view reload:info]; return view; } - (NSAttributedString *)formatMessageString:(NSString *)text { //先判断text是否存在 if (text == nil || text.length == 0) { NSLog(@"TTextMessageCell formatMessageString failed , current text is nil"); return [[NSMutableAttributedString alloc] initWithString:@""]; } //1、创建一个可变的属性字符串 NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:text]; UIFont *textFont = [UIFont fontWithName:kPFSCFont size:14]; [attributeString addAttribute:NSFontAttributeName value:textFont range:NSMakeRange(0, attributeString.length)]; return attributeString; // if([TUIKit sharedInstance].config.faceGroups.count == 0){ // [attributeString addAttribute:NSFontAttributeName value:textFont range:NSMakeRange(0, attributeString.length)]; // return attributeString; // } // // //2、通过正则表达式来匹配字符串 // NSString *regex_emoji = @"\\[[a-zA-Z0-9\\/\\u4e00-\\u9fa5]+\\]"; //匹配表情 // // NSError *error = nil; // NSRegularExpression *re = [NSRegularExpression regularExpressionWithPattern:regex_emoji options:NSRegularExpressionCaseInsensitive error:&error]; // if (!re) { // NSLog(@"%@", [error localizedDescription]); // return attributeString; // } // // NSArray *resultArray = [re matchesInString:text options:0 range:NSMakeRange(0, text.length)]; // // TFaceGroup *group = [TUIKit sharedInstance].config.faceGroups[0]; // // //3、获取所有的表情以及位置 // //用来存放字典,字典中存储的是图片和图片对应的位置 // NSMutableArray *imageArray = [NSMutableArray arrayWithCapacity:resultArray.count]; // //根据匹配范围来用图片进行相应的替换 // for(NSTextCheckingResult *match in resultArray) { // //获取数组元素中得到range // NSRange range = [match range]; // //获取原字符串中对应的值 // NSString *subStr = [text substringWithRange:range]; // // for (TFaceCellData *face in group.faces) { // if ([face.name isEqualToString:subStr]) { // //face[i][@"png"]就是我们要加载的图片 // //新建文字附件来存放我们的图片,iOS7才新加的对象 // NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init]; // //给附件添加图片 // textAttachment.image = [[TUIImageCache sharedInstance] getFaceFromCache:face.path]; // //调整一下图片的位置,如果你的图片偏上或者偏下,调整一下bounds的y值即可 // textAttachment.bounds = CGRectMake(0, -(textFont.lineHeight-textFont.pointSize)/2, textFont.pointSize, textFont.pointSize); // //把附件转换成可变字符串,用于替换掉源字符串中的表情文字 // NSAttributedString *imageStr = [NSAttributedString attributedStringWithAttachment:textAttachment]; // //把图片和图片对应的位置存入字典中 // NSMutableDictionary *imageDic = [NSMutableDictionary dictionaryWithCapacity:2]; // [imageDic setObject:imageStr forKey:@"image"]; // [imageDic setObject:[NSValue valueWithRange:range] forKey:@"range"]; // //把字典存入数组中 // [imageArray addObject:imageDic]; // break; // } // } // } // // //4、从后往前替换,否则会引起位置问题 // for (int i = (int)imageArray.count -1; i >= 0; i--) { // NSRange range; // [imageArray[i][@"range"] getValue:&range]; // //进行替换 // [attributeString replaceCharactersInRange:range withAttributedString:imageArray[i][@"image"]]; // } // // // [attributeString addAttribute:NSFontAttributeName value:textFont range:NSMakeRange(0, attributeString.length)]; // // return attributeString; } @end