// // PopMenuCenter.m // BuguLive // // Created by 岳克奎 on 17/3/10. // Copyright © 2017年 xfg. All rights reserved. // #import "PopMenuCenter.h" #import #import "PublishLivestViewController.h" #import "AgreementViewController.h" //#import "TCVideoRecordViewController.h" @implementation PopMenuCenter #pragma mark ----------------------- life cycle生命周期管控区域 ------------------- /** * @brief: 单利 * * @discussion:我的想法是,用单例管理,这样能够通过的player对应的控制器来控制。播放,暂停。如果不这样,需要频繁的 */ static PopMenuCenter *signleton = nil; + (instancetype)allocWithZone:(struct _NSZone *)zone { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ signleton = [super allocWithZone:zone]; }); return signleton; } +(PopMenuCenter *)sharePopMenuCenter { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ signleton = [[self alloc] init]; }); return signleton; } + (id)copyWithZone:(struct _NSZone *)zone { return signleton; } + (id)mutableCopyWithZone:(struct _NSZone *)zone { return signleton; } #pragma mark ********************************** Delegate 协议区域************************** #pragma mark ----------- /** * @brief: 根据点击索引,加载对应模块 * @prama: popMenuView 动态菜单底层管理层 * @prama: index 点击索引 */ -(void)popMenuView:(HyPopMenuView *)popMenuView didSelectItemAtIndex:(NSUInteger)index{ //开直播 if (index == 0) { IMALoginParam *loginParam = [IMALoginParam loadFromLocal]; if (loginParam.isAgree ==1) { if (AppDelegate.sharedAppDelegate.isInAudioVideoChatVc) { [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"通话中,请结束通话后再试")]; return; } PublishLivestViewController *pvc = [[PublishLivestViewController alloc] init]; [[AppDelegate sharedAppDelegate] presentViewController:pvc animated:YES completion:^{ }]; } else { AgreementViewController *agreeVC = [AgreementViewController webControlerWithUrlStr:[GlobalVariables sharedInstance].appModel.agreement_link isShowIndicator:YES isShowNavBar:YES]; [[AppDelegate sharedAppDelegate] presentViewController:agreeVC animated:YES completion:^{ }]; } } //小视频 else if (index== 1) { [self showVideoDynamicViewC]; } } #pragma mark **************************** Private methods 私有方法区域********************* #pragma mark -加载前PopView权限与判断 -(void)showPopView { ALAuthorizationStatus author = [ALAssetsLibrary authorizationStatus];//获取权限状态 if(author == kCLAuthorizationStatusRestricted || author ==kCLAuthorizationStatusDenied)//无权限 { //无权限 } // iOS 8 后,全部都要授权 AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; switch (status) { case AVAuthorizationStatusNotDetermined: { // 许可对话没有出现,发起授权许可 [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) { if (granted) { //第一次用户接 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self showMenu]; }); }else { //用户拒绝 } }]; break; } case AVAuthorizationStatusAuthorized: { [self showMenu];// 已经开启授权,可继续 break; } case AVAuthorizationStatusDenied: case AVAuthorizationStatusRestricted: // 用户明确地拒绝授权,或者相机设备无法访问 if ([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo] == AVAuthorizationStatusDenied || AVAuthorizationStatusRestricted) { UIAlertController *alertC = [UIAlertController alertControllerWithTitle:ASLocalizedString(@"相册权限")message:ASLocalizedString(@"无法访问相册,请在系统设置中允许访问")preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:ASLocalizedString(@"取消")style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { }]; [alertC addAction:cancelAction]; UIAlertAction *confirmAction = [UIAlertAction actionWithTitle:ASLocalizedString(@"设置")style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString]; [[UIApplication sharedApplication] openURL:url]; }]; [alertC addAction:confirmAction]; [[AppDelegate sharedAppDelegate] presentViewController:alertC animated:YES completion:nil]; } break; default: break; } } #pragma mark- 加载PopView -(void)showMenu { if (!_menu) { [self menu]; } NSMutableArray *tempDSMArray = @[].mutableCopy; NSMutableArray *picStrMArray = @[@"st_play_live", @"st_vedio_goods", ].mutableCopy; NSMutableArray *titleStrMArray = @[ASLocalizedString(@"发起直播"), ASLocalizedString(@"发布短视频"), ].mutableCopy; if (picStrMArray.count == titleStrMArray.count) { for (int i = 0;i