Commit 3e56ecec9a8d6980ef94d3c5189ffb7920ed6f2b

Authored by 王军波
1 parent d62e7310

验证是否有主播权限

LiveVideoCloud/Classes/Sections/LiveSections/Controller/LVCLiveViewController.m
... ... @@ -13,8 +13,10 @@
13 13 #import "LVCUGCLivePrepareView.h"
14 14 #import "LiveBaseView.h"
15 15 #import "LVCUGCLiveEndView.h"
  16 +#import "LVCVerifyLiveAuthService.h"
  17 +#import "LVCVerifyViewController.h"
16 18  
17   -@interface LVCLiveViewController ()<UIGestureRecognizerDelegate> {
  19 +@interface LVCLiveViewController ()<UIGestureRecognizerDelegate, UIAlertViewDelegate, UINavigationControllerDelegate> {
18 20  
19 21 BOOL _isStreaming;
20 22 }
... ... @@ -46,38 +48,102 @@
46 48 - (void)viewDidLoad {
47 49 [super viewDidLoad];
48 50  
49   - self.view.backgroundColor = [UIColor blueColor];
50   -
51   - [self.view addSubview:self.captureView];
52   -
53   - [self.view addSubview:self.prepareView];
  51 + self.navigationController.delegate = self;
  52 + self.view.backgroundColor = [UIColor whiteColor];
54 53 [self.view addSubview:self.quitButton];
55   - [self.view addSubview:self.changeCameraButton];
56   - [self.view addSubview:self.openFilterButton];
57   - [self.view addSubview:self.openFlashButton];
58   - [self.view addSubview:self.filterView];
59   -
60   - // 初始化推流
61   - NSInteger time = [[NSDate date] timeIntervalSince1970];
62   - NSString *timeString = [NSString stringWithFormat:@"%ld", (long)time];
63   - NSString *random = [NSString stringWithFormat:@"%d%d%d%d%d",arc4random()%9,arc4random()%9,arc4random()%9,arc4random()%9,arc4random()%9];
64   - NSString *activityId = [NSString stringWithFormat:@"%@%@",timeString,random];
  54 + [self verifyLiveAuthority];
  55 +}
65 56  
66   - _kitCN = [[CNLiveGPUStreamerKit alloc] initWithDefaultConfigWithActivityId:activityId channelId:@"iOStest" isHorizontalScreen:@"0"];
  57 +#pragma mark - 验证是否有主播权限
  58 +- (void)verifyLiveAuthority {
67 59  
68   - _kitCN.coverImgUrl = @"https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=169300069,2234409601&fm=21&gp=0.jpg"; // 封面图
69   - // 昵称 头像
70   - NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:@"我的名字好长啊", @"name", @"http://www.qq745.com/uploads/allimg/150318/1-15031PGF8-51.jpg", @"iconUrl", nil];
71   - _kitCN.extensions = [self dictionaryToJson:userInfo];
72   -
73   - // 设置推流配置
74   - [self setStreamerCfg];
  60 + [LVCVerifyLiveAuthService verifyLiveAuthWithHandler:^(id data, NSError *error) {
  61 +
  62 + if (error) {
  63 + NSLog(@"失败===>error:%@",error);
  64 + UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:[NSString stringWithFormat:@"抱歉, 鉴权失败~ "] delegate:nil cancelButtonTitle:@"好的" otherButtonTitles: nil];
  65 + alert.tag = 1005;
  66 + [alert show];
  67 +
  68 + return ;
  69 + }
  70 +
  71 + NSLog(@"成功===>data:%@",data);
  72 +
  73 + int status = [data[@"status"] intValue];
  74 + if (status == -1) { //未审核
  75 + UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"亲, 完成实名认证就可以开播啦,现在就去认证吧!" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"去认证", nil];
  76 + alert.tag = 1001;
  77 + [alert show];
  78 + } else if (status == 1) { //审核中
  79 + UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"亲, 正在审核中..." delegate:self cancelButtonTitle:@"好的" otherButtonTitles: nil];
  80 + alert.tag = 1002;
  81 + [alert show];
  82 + } else if (status == 2) { //审核失败
  83 + UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"抱歉, 审核失败~" delegate:self cancelButtonTitle:@"好的" otherButtonTitles: nil];
  84 + alert.tag = 1003;
  85 + [alert show];
  86 + } else if (status == 3) { //启用
  87 + //开始推流
  88 + [self.view addSubview:self.captureView];
  89 + [self.view addSubview:self.prepareView];
  90 + [self.view addSubview:self.changeCameraButton];
  91 + [self.view addSubview:self.openFilterButton];
  92 + [self.view addSubview:self.openFlashButton];
  93 + [self.view addSubview:self.filterView];
  94 +
  95 + // 初始化推流
  96 + NSInteger time = [[NSDate date] timeIntervalSince1970];
  97 + NSString *timeString = [NSString stringWithFormat:@"%ld", (long)time];
  98 + NSString *random = [NSString stringWithFormat:@"%d%d%d%d%d",arc4random()%9,arc4random()%9,arc4random()%9,arc4random()%9,arc4random()%9];
  99 + NSString *activityId = [NSString stringWithFormat:@"%@%@",timeString,random];
  100 +
  101 + _kitCN = [[CNLiveGPUStreamerKit alloc] initWithDefaultConfigWithActivityId:activityId channelId:@"iOStest" isHorizontalScreen:@"0"];
  102 + // 封面图
  103 + _kitCN.coverImgUrl = @"https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=169300069,2234409601&fm=21&gp=0.jpg";
  104 + // 昵称 头像
  105 + NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys:@"我的名字好长啊", @"name", @"http://www.qq745.com/uploads/allimg/150318/1-15031PGF8-51.jpg", @"iconUrl", nil];
  106 + _kitCN.extensions = [self dictionaryToJson:userInfo];
  107 +
  108 + // 设置推流配置
  109 + [self setStreamerCfg];
  110 +
  111 + [self addObservers];
  112 +
  113 + UITapGestureRecognizer * singleRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTap:)];
  114 + singleRecognizer.delegate = self;
  115 + [self.captureView addGestureRecognizer:singleRecognizer];
  116 +
  117 + } else { //禁用
  118 + UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"抱歉, 您没有权限~" delegate:nil cancelButtonTitle:@"好的" otherButtonTitles: nil];
  119 + alert.tag = 1004;
  120 + [alert show];
  121 + }
  122 +
  123 + }];
  124 +}
  125 +
  126 +#pragma mark - UIAlertViewDelegate
  127 +- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
75 128  
76   - [self addObservers];
  129 + if (alertView.tag == 1001 && buttonIndex == 1) { // 未审核 去认证
  130 +
  131 + NSLog(@"未审核 去认证");
  132 + LVCVerifyViewController *vc = [[LVCVerifyViewController alloc] init];
  133 + [self.navigationController pushViewController:vc animated:YES];
  134 +
  135 + } else {
  136 +
  137 + NSLog(@"弹出");
  138 + [self dismissViewControllerAnimated:YES completion:nil];
  139 + }
  140 +}
  141 +
  142 +#pragma mark - UINavigationControllerDelegate
  143 +- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
  144 + BOOL isHomePage = [viewController isKindOfClass:[self class]];
77 145  
78   - UITapGestureRecognizer * singleRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTap:)];
79   - singleRecognizer.delegate = self;
80   - [self.captureView addGestureRecognizer:singleRecognizer];
  146 + [self.navigationController setNavigationBarHidden:isHomePage animated:YES];
81 147 }
82 148  
83 149 #pragma mark - initialization Streamer
... ... @@ -131,7 +197,7 @@
131 197 if (_prepareView.titleTextField.text) {
132 198 _kitCN.activityName = _prepareView.titleTextField.text;
133 199 } else {
134   - _kitCN.activityName = @"无名";
  200 + _kitCN.activityName = @"主播很懒,没有标题~";
135 201 }
136 202  
137 203 [_openFilterButton removeFromSuperview];
... ...