PublishLivestViewController.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. //
  2. // PublishLivestViewController.m
  3. // BuguLive
  4. //
  5. // Created by xgh on 2017/8/25.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import <objc/runtime.h>
  9. #import "PublishLivestViewController.h"
  10. #import "PublishLiveShareView.h"
  11. #import "PublishLiveViewModel.h"
  12. #import "BGOtherPushViewController.h"
  13. #import "PublishVoiceViewController.h"
  14. @interface PublishLivestViewController ()<publishViewDelegate, UINavigationControllerDelegate,UIImagePickerControllerDelegate, UIActionSheetDelegate,UITextViewDelegate,UITextFieldDelegate>
  15. //@property (nonatomic, strong) BGOssManager *ossManager;
  16. @property (nonatomic, strong)NSString *timeString;//时间戳的字符串
  17. @property (nonatomic, strong)NSString *uploadFilePath;
  18. @property (nonatomic, strong)NSString *imageString;
  19. @property (nonatomic, strong)PublishLiveShareView *shareView;
  20. @property (nonatomic, strong)VideoClassifiedModel *videoClassmodel;
  21. @property(nonatomic, strong) UITextField *textField;
  22. @end
  23. @implementation PublishLivestViewController
  24. - (void)viewDidLoad
  25. {
  26. [super viewDidLoad];
  27. self.navigationController.navigationBarHidden =YES;
  28. [GlobalVariables sharedInstance].isShop = NO;
  29. }
  30. - (void)initFWUI
  31. {
  32. [super initFWUI];
  33. self.liveView = [[PublishLiveView alloc]initWithFrame:self.view.bounds];
  34. self.liveView.delegate = self;
  35. // self.liveView.textView.delegate = self;
  36. [self.view addSubview:self.liveView];
  37. self.shareView = [[PublishLiveShareView alloc]initWithFrame:CGRectMake(0, self.view.height - 190 - kRealValue(40), self.view.width, 50)];
  38. self.liveView.shareView = self.shareView;
  39. [self.liveView addSubview:self.shareView];
  40. self.shareView.hidden = YES;
  41. [self.liveView.voiceBtn addTarget:self action:@selector(voiceClick) forControlEvents:UIControlEventTouchUpInside];
  42. }
  43. - (void)voiceClick {
  44. [self dismissViewControllerAnimated:NO completion:^{
  45. PublishVoiceViewController *vc = [PublishVoiceViewController new];
  46. [[AppDelegate sharedAppDelegate]presentViewController:vc animated:NO completion:nil];
  47. }];
  48. }
  49. - (void)initFWData
  50. {
  51. [super initFWData];
  52. NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
  53. [dict setValue:@"voice" forKey:@"ctl"];
  54. [dict setValue:@"get_video_cover_image" forKey:@"act"];
  55. WeakSelf
  56. [[NetHttpsManager manager] POSTWithParameters:dict SuccessBlock:^(NSDictionary *responseJson) {
  57. NSString *live_image = responseJson[@"data"][@"live_image"];
  58. if(live_image.length > 0)
  59. {
  60. weakSelf.imageString = live_image;
  61. [weakSelf.liveView.selectedImageView sd_setImageWithURL:[NSURL URLWithString:live_image]];
  62. weakSelf.liveView.selectedImageView.frame = CGRectMake(0, 0, weakSelf.liveView.coverBgView.width, weakSelf.liveView.coverBgView.height);
  63. }
  64. } FailureBlock:^(NSError *error) {
  65. }];
  66. }
  67. - (void)initFWVariables
  68. {
  69. [super initFWVariables];
  70. // if (self.BuguLive.appModel.open_sts == 1)
  71. // {
  72. // _ossManager = [[BGOssManager alloc]initWithDelegate:self];
  73. // }
  74. }
  75. - (void)viewWillAppear:(BOOL)animated
  76. {
  77. [super viewWillAppear:animated];
  78. // [self.liveView.videoCamera startCameraCapture];
  79. [self.navigationController setNavigationBarHidden:YES];
  80. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
  81. self.BuguLive.liveState.isInPubViewController = YES;
  82. [[UIBarButtonItem appearance]setTitleTextAttributes:@{NSForegroundColorAttributeName:kBlackColor,
  83. NSFontAttributeName:[UIFont systemFontOfSize:15]
  84. } forState:UIControlStateNormal];
  85. }
  86. - (void)viewWillDisappear:(BOOL)animated
  87. {
  88. [super viewWillDisappear:animated];
  89. }
  90. - (void)dealloc {
  91. [self.liveView stopPush];
  92. [self.navigationController setNavigationBarHidden:NO];
  93. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
  94. self.BuguLive.liveState.isInPubViewController = NO;
  95. [self.liveView.tiSDKManager destroy];
  96. }
  97. #pragma mark ----------- publishViewDelegate---------
  98. - (void)closeThestartLiveViewDelegate
  99. {
  100. [self.view endEditing:YES];
  101. if (self.navigationController.viewControllers.count >1)
  102. {
  103. [self.navigationController popViewControllerAnimated:YES];
  104. }else
  105. {
  106. [self.navigationController dismissViewControllerAnimated:YES completion:nil];
  107. }
  108. }
  109. - (void)selectedTheImageDelegate
  110. {
  111. UIImagePickerController *picker = [[UIImagePickerController alloc] init];
  112. if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum])
  113. {
  114. picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
  115. picker.delegate = self;
  116. picker.allowsEditing = YES;
  117. picker.modalPresentationStyle = UIModalPresentationOverCurrentContext;
  118. }
  119. [self presentViewController:picker animated:YES completion:nil];
  120. }
  121. - (void)selectedTheClassifyDelegate
  122. {
  123. UIAlertController *alterVC = [UIAlertController alertControllerWithTitle:ASLocalizedString(@"选择分类")message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  124. NSMutableAttributedString *alertControllerStr = [[NSMutableAttributedString alloc] initWithString:alterVC.title];
  125. [alertControllerStr addAttribute:NSForegroundColorAttributeName value:kAppMainColor range:NSMakeRange(0, alertControllerStr.length)];
  126. [alertControllerStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:17] range:NSMakeRange(0, alertControllerStr.length)];
  127. Ivar m_currentTitleColor = NULL;
  128. unsigned int count = 0;
  129. Ivar *members = class_copyIvarList([UIAlertController class], &count);
  130. for (int i = 0 ; i < count; i++)
  131. {
  132. Ivar var = members[i];
  133. const char *memberName = ivar_getName(var);
  134. if (strcmp(memberName, "attributedTitle") == 0)
  135. {
  136. m_currentTitleColor = var;
  137. }
  138. object_setIvar(alterVC, m_currentTitleColor, alertControllerStr);
  139. }
  140. for (int i = 0; i < self.BuguLive.appModel.video_classified.count; i++)
  141. {
  142. VideoClassifiedModel * model = self.BuguLive.appModel.video_classified[i];
  143. UIAlertAction *action = [UIAlertAction actionWithTitle:model.title style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  144. [self.liveView.topView.classifyBtn setTitle:[NSString stringWithFormat:ASLocalizedString(@"直播分类:%@"),model.title] forState:UIControlStateNormal];
  145. self.videoClassmodel = model;
  146. }];
  147. Ivar m_currentColor = NULL;
  148. unsigned int num = 0;
  149. Ivar *actions = class_copyIvarList([UIAlertAction class], &num);
  150. for (int i = 0 ; i < num; i++)
  151. {
  152. Ivar var = actions[i];
  153. const char *memberName = ivar_getName(var);
  154. if (strcmp(memberName, "_titleTextColor") == 0)
  155. {
  156. m_currentColor = var;
  157. }
  158. object_setIvar(action, m_currentColor, kAppMainColor);
  159. }
  160. [alterVC addAction:action];
  161. }
  162. UIAlertAction *action = [UIAlertAction actionWithTitle:ASLocalizedString(@"取消 ")style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
  163. }];
  164. [alterVC addAction:action];
  165. [self presentViewController:alterVC animated:YES completion:nil];
  166. }
  167. - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
  168. {
  169. NSString *mediaType = [info objectForKey:UIImagePickerControllerEditedImage];
  170. if (mediaType)
  171. {
  172. UIImage *image = [info objectForKey:@"UIImagePickerControllerEditedImage"];
  173. if (!image)
  174. {
  175. image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
  176. }
  177. [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  178. // if (self.BuguLive.appModel.open_sts == 1)
  179. // {
  180. // if ([_ossManager isSetRightParameter])
  181. // {
  182. // [self saveImage:image withName:@"1.png"];
  183. // _timeString = [_ossManager getObjectKeyString];
  184. // [_ossManager asyncPutImage:_timeString localFilePath:_uploadFilePath];
  185. // }
  186. // }
  187. // else
  188. // {
  189. NSData *data=UIImageJPEGRepresentation(image, 1.0);
  190. [self saveImage:[UIImage imageWithData:data] withName:@"currentImage6.png"];
  191. [self performSelector:@selector(uploadAvatar) withObject:nil afterDelay:0.8];
  192. // }
  193. }
  194. [picker dismissViewControllerAnimated:YES completion:nil];
  195. }
  196. - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
  197. {
  198. [UIView animateWithDuration:0.1 animations:^{
  199. self.tabBarController.tabBar.frame = CGRectMake(0, kScreenH - self.tabBarController.tabBar.frame.size.height , kScreenW, self.tabBarController.tabBar.frame.size.height);
  200. } completion:^(BOOL finished) {
  201. [picker dismissViewControllerAnimated:YES completion:nil];
  202. }];
  203. }
  204. - (void)saveImage:(UIImage *)currentImage withName:(NSString *)imageName
  205. {
  206. NSData *imageData = UIImageJPEGRepresentation(currentImage, 0.5);
  207. NSString *fullPath = [[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:imageName];
  208. [imageData writeToFile:fullPath atomically:NO];
  209. _uploadFilePath = fullPath;
  210. NSLog(@"uploadFilePath : %@", _uploadFilePath);
  211. }
  212. #pragma mark 代理回调
  213. //- (void)uploadImageWithUrlStr:(NSString *)imageUrlStr withUploadStateCount:(int)stateCount
  214. //{
  215. // if (stateCount == 0)
  216. // {
  217. // NSString *imgString= [NSString stringWithFormat:@"%@%@",_ossManager.oss_domain,_timeString];
  218. // _imageString=[NSString stringWithFormat:@"./%@",_timeString];
  219. // [self.liveView.selectedImageView sd_setImageWithURL:[NSURL URLWithString:imgString]];
  220. // [MBProgressHUD hideHUDForView:self.view animated:YES];
  221. // }
  222. // else
  223. // {
  224. // [MBProgressHUD hideHUDForView:self.view animated:YES];
  225. // }
  226. //}
  227. #pragma mark 使用流文件上传头像
  228. - (void)uploadAvatar
  229. {
  230. NSString *imageFile = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
  231. NSString *photoName;
  232. photoName=[imageFile stringByAppendingPathComponent:@"currentImage6.png"];
  233. NSURL *fileUrl = [NSURL URLWithString:[NSString stringWithFormat:@"file:%@",photoName]];
  234. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  235. [parmDict setObject:@"avatar" forKey:@"ctl"];
  236. [parmDict setObject:@"uploadImage" forKey:@"act"];
  237. FWWeakify(self)
  238. [self.httpsManager POSTWithDict:parmDict andFileUrl:fileUrl SuccessBlock:^(NSDictionary *responseJson){
  239. [MBProgressHUD hideHUDForView:self.view animated:YES];
  240. FWStrongify(self)
  241. if ([responseJson toInt:@"status"] == 1)
  242. {
  243. _imageString=[responseJson toString:@"path"];
  244. [self.liveView.selectedImageView sd_setImageWithURL:[NSURL URLWithString:[responseJson toString:@"server_full_path"]]];
  245. self.liveView.selectedImageView.frame = CGRectMake(0, 0, self.liveView.coverBgView.width, self.liveView.coverBgView.height);
  246. }
  247. } FailureBlock:^(NSError *error) {
  248. FWStrongify(self)
  249. [MBProgressHUD hideHUDForView:self.view animated:YES];
  250. [[BGHUDHelper sharedInstance] tipMessage:[NSString stringWithFormat:@"%@",error]];
  251. }];
  252. }
  253. #pragma mark ---- 开始直播------
  254. #pragma mark 点击事件
  255. - (void)startThePublishLiveDelegate
  256. {
  257. if (self.liveView.otherPushBtn.isSelected) {
  258. [self showHostLiveBtn];
  259. }else{
  260. [self avAuthorizationCamera];
  261. }
  262. }
  263. #pragma mark 相机权限
  264. - (void)avAuthorizationCamera
  265. {
  266. AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
  267. switch (status)
  268. {
  269. case AVAuthorizationStatusNotDetermined:
  270. {
  271. // 许可对话没有出现,发起授权许可
  272. [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) {
  273. if (granted)
  274. {
  275. //第一次用户接受
  276. [self avAuthorizationMic];
  277. }
  278. else
  279. {
  280. //第一次用户接受
  281. NSLog(ASLocalizedString(@"第一次用户拒绝"));
  282. }
  283. }];
  284. break;
  285. }
  286. case AVAuthorizationStatusAuthorized:
  287. {
  288. // 已经开启授权,可继续
  289. [self avAuthorizationMic];
  290. break;
  291. }
  292. case AVAuthorizationStatusDenied:
  293. case AVAuthorizationStatusRestricted:
  294. // 用户明确地拒绝授权,或者相机设备无法访问
  295. [self showAlertViewCAndMessageStr:ASLocalizedString(@"请前往设置'隐私-麦克风'开启应用权限")];
  296. break;
  297. default:
  298. break;
  299. }
  300. }
  301. #pragma mark 麦克风权限
  302. - (void)avAuthorizationMic
  303. {
  304. AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio];
  305. switch (status)
  306. {
  307. case AVAuthorizationStatusNotDetermined:
  308. {
  309. // 许可对话没有出现,发起授权许可
  310. [AVCaptureDevice requestAccessForMediaType:AVMediaTypeAudio completionHandler:^(BOOL granted) {
  311. if (granted)
  312. {
  313. dispatch_async(dispatch_get_main_queue(), ^{
  314. //第一次用户接受
  315. [self showHostLiveBtn];
  316. });
  317. }
  318. else
  319. {
  320. //第一次用户接受
  321. }
  322. }];
  323. break;
  324. }
  325. case AVAuthorizationStatusAuthorized:
  326. {
  327. // 已经开启授权,可继续
  328. NSLog(ASLocalizedString(@"已经开启授权,可继续"));
  329. [self showHostLiveBtn];
  330. break;
  331. }
  332. case AVAuthorizationStatusDenied:
  333. case AVAuthorizationStatusRestricted:
  334. // 用户明确地拒绝授权,或者相机设备无法访问
  335. [self showAlertViewCAndMessageStr:ASLocalizedString(@"请前往设置'隐私-麦克风'打开应用权限")];
  336. break;
  337. default:
  338. break;
  339. }
  340. }
  341. - (void)showAlertViewCAndMessageStr:(NSString *)messageStr
  342. {
  343. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:ASLocalizedString(@"温馨提示")message:messageStr preferredStyle:UIAlertControllerStyleAlert];
  344. [alertController addAction:[UIAlertAction actionWithTitle:ASLocalizedString(@"确定")style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  345. NSLog(ASLocalizedString(@"点击确认"));
  346. }]];
  347. [self presentViewController:alertController animated:YES completion:nil];
  348. }
  349. -(void)clickPasswordActionDelegate:(BOOL)password{
  350. if (password == NO) {
  351. self.liveView.topView.password = @"";
  352. return;
  353. }
  354. WeakSelf
  355. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:ASLocalizedString(@"请设置房间密码")preferredStyle:UIAlertControllerStyleAlert];
  356. [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
  357. textField.text = self.liveView.topView.password;
  358. textField.placeholder = ASLocalizedString(@"请设置一个数字密码");
  359. textField.delegate = self;
  360. textField.keyboardType = UIKeyboardTypeNumberPad;
  361. _textField = textField;
  362. }];
  363. UIAlertAction *actionCacel = [UIAlertAction actionWithTitle:ASLocalizedString(@"取消")style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  364. self.liveView.topView.passwordBtn.selected = NO;
  365. }];
  366. [alertController addAction:actionCacel];
  367. UIAlertAction *actionConfirm = [UIAlertAction actionWithTitle:ASLocalizedString(@"确定")style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  368. if (weakSelf.textField.text.length < 1) {
  369. self.liveView.topView.passwordBtn.selected = NO;
  370. }else{
  371. weakSelf.liveView.topView.password = weakSelf.textField.text;
  372. }
  373. [_textField resignFirstResponder];
  374. }];
  375. [alertController addAction:actionConfirm];
  376. [self presentViewController:alertController animated:YES completion:nil];
  377. }
  378. -(void)textFieldDidChangeSelection:(UITextField *)textField{
  379. self.liveView.topView.password = textField.text;
  380. NSLog(@"%@",textField.text);
  381. }
  382. -(void)clickShopActionDelegate:(BOOL)shop{
  383. }
  384. #pragma mark 开始直播
  385. - (void)showHostLiveBtn
  386. {
  387. // 网络判断
  388. if (![BGUtils isNetConnected])
  389. {
  390. return;
  391. }
  392. [BGUtils closeKeyboard];
  393. // if (!self.liveView.topView.pravicy)
  394. // {
  395. // if (!self.videoClassmodel)
  396. // {
  397. // if (self.BuguLive.appModel.is_classify == 1)
  398. // {
  399. // [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"请选择分类")];
  400. // return;
  401. // }
  402. // }
  403. // }
  404. NSMutableDictionary *mDict = [NSMutableDictionary dictionary];
  405. [mDict setObject:@"video" forKey:@"ctl"];
  406. [mDict setObject:@"add_video" forKey:@"act"];
  407. if ([BGUtils isBlankString:_imageString])
  408. {
  409. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"请选择封面")];
  410. return;
  411. }
  412. [mDict setObject:_imageString forKey:@"live_image"];
  413. // 房间标题
  414. if (self.liveView.textView.text.length > 0)
  415. {
  416. if ([self.liveView.textView.text isEqualToString:ASLocalizedString(@"#添加标题上热门更轻松")]) {
  417. self.liveView.textView.text = [GlobalVariables sharedInstance].userModel.nick_name;
  418. }
  419. [mDict setObject:self.liveView.textView.text forKey:@"title"];
  420. }else{
  421. [mDict setObject:[GlobalVariables sharedInstance].userModel.nick_name forKey:@"title"];
  422. }
  423. if (self.liveView.otherPushBtn.isSelected) {
  424. [mDict setObject:@"2" forKey:@"push_type"];
  425. }else{
  426. [mDict setObject:@"1" forKey:@"push_type"];
  427. }
  428. // 是否私密
  429. if (self.liveView.topView.pravicy)
  430. {
  431. [mDict setObject:[NSString stringWithFormat:@"%d",1] forKey:@"is_private"];
  432. }
  433. else
  434. {
  435. [mDict setObject:[NSString stringWithFormat:@"%d",0] forKey:@"is_private"];
  436. [mDict setObject:self.shareView.shareStr forKey:@"share_type"];
  437. }
  438. // 地理位置
  439. if (self.liveView.topView.provinceSrting.length && self.liveView.topView.locationCityString.length && self.liveView.topView.isCanLocation)
  440. {
  441. [mDict setObject:self.liveView.topView.locationCityString forKey:@"city"];
  442. [mDict setObject:self.liveView.topView.provinceSrting forKey:@"province"];
  443. }
  444. else
  445. {
  446. [mDict setObject:[NSString stringWithFormat:@"%d",0] forKey:@"location_switch"];
  447. }
  448. [mDict setObject:SafeStr(self.liveView.cid) forKey:@"video_classified"];
  449. //购物车
  450. [mDict setObject:[GlobalVariables sharedInstance].isShop ? @"1" : @"0" forKey:@"is_shop"];
  451. if (![BGUtils isBlankString:self.liveView.topView.password]) {
  452. // if (self.liveView.topView.password.length != 4) {
  453. // [FanweMessage alertHUD:ASLocalizedString(@"房间密码应为四位数!")];
  454. // return;
  455. // }else{
  456. [mDict setObject:self.liveView.topView.password forKey:@"password"];
  457. // }
  458. }
  459. //门票
  460. if (self.liveView.enterTicketButton.isSelected && self.liveView.ticketTF.text.intValue > 0) {
  461. [mDict setObject:self.liveView.ticketTF.text forKey:@"ticket"];
  462. } else {
  463. [mDict setObject:@"0" forKey:@"ticket"];
  464. }
  465. //是否加密
  466. if (self.liveView.passWordButton.isSelected && self.liveView.passTF.text.length > 0) {
  467. [mDict setObject:self.liveView.passTF.text forKey:@"password"];
  468. } else {
  469. [mDict setObject:@"" forKey:@"password"];
  470. }
  471. if (self.liveView.passWordButton.isSelected && (self.liveView.passTF.text.length > 8 || self.liveView.passTF.text.length < 4)) {
  472. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"请输入4-8位数字密码")];
  473. return;
  474. }
  475. if (self.liveView.enterTicketButton.isSelected && self.liveView.ticketTF.text.intValue <= 0) {
  476. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"最低设置为1钻石")];
  477. return;
  478. }
  479. __weak UIButton *btn = self.liveView.startButton;
  480. self.liveView.startButton.userInteractionEnabled = NO;
  481. if (self.liveView.otherPushBtn.isSelected) {
  482. [GlobalVariables sharedInstance].isOtherPush = YES;
  483. [[LiveCenterAPIManager sharedInstance] liveCenterAPIOfShowHostLiveOfDic:mDict block:^(NSDictionary *responseJson, BOOL finished, NSError *error) {
  484. btn.userInteractionEnabled = YES;
  485. [btn setTitle:ASLocalizedString(@"开始直播")forState:UIControlStateNormal];
  486. BGOtherPushViewController *otherVC = [[BGOtherPushViewController alloc]init];
  487. NSString *room_id = [NSString stringWithFormat:@"%@",responseJson[@"room_id"]];
  488. otherVC.room_id = room_id;
  489. [self.navigationController pushViewController:otherVC animated:YES];
  490. }];
  491. }else{
  492. [GlobalVariables sharedInstance].isOtherPush = NO;
  493. [PublishLiveViewModel beginLive:mDict vc:self block:^(AppBlockModel *blockModel) {
  494. btn.userInteractionEnabled = YES;
  495. [btn setTitle:ASLocalizedString(@"开始直播")forState:UIControlStateNormal];
  496. }];
  497. }
  498. }
  499. #pragma mark - 点击美颜按钮
  500. -(void)selectedTheBeautyDelegate{
  501. }
  502. #pragma mark API请求拿到直播类型,开始启动直播
  503. - (void)closePublishViewCWith:(NSInteger )roomID {
  504. __weak PublishLivestViewController *weak_Self = self;
  505. UIViewController *rootVC = weak_Self.presentingViewController;
  506. while (rootVC.presentingViewController)
  507. {
  508. rootVC = rootVC.presentingViewController;
  509. }
  510. [rootVC dismissViewControllerAnimated:YES completion:^{
  511. //开启直播
  512. LIVE_CENTER_MANAGER.stSuspensionWindow.hidden = NO;//为了加载
  513. IMAHost *host = [IMAPlatform sharedInstance].host;
  514. if (!host)
  515. {
  516. [[BGIMLoginManager sharedInstance] loginImSDK:YES succ:nil failed:nil];
  517. return;
  518. }
  519. //配置信息
  520. TCShowUser *user = [[TCShowUser alloc] init];
  521. user.avatar = [host imUserIconUrl];
  522. user.uid = [host imUserId];
  523. user.username = [host imUserName];
  524. TCShowLiveListItem *liveRoom = [[TCShowLiveListItem alloc] init];
  525. liveRoom.host = user;
  526. liveRoom.avRoomId = (int)roomID;
  527. liveRoom.title = [NSString stringWithFormat:@"%d",liveRoom.avRoomId];
  528. liveRoom.vagueImgUrl = [[IMAPlatform sharedInstance].host.customInfoDict toString:@"head_image"];
  529. // [LIVE_CENTER_MANAGER showLiveOfTCShowLiveListItem:liveRoom andLiveWindowType:liveWindowTypeOfSusOfFullSize andLiveType:FW_LIVE_TYPE_HOST andLiveSDKType:FW_LIVESDK_TYPE_KSY andCompleteBlock:^(BOOL finished) {
  530. //
  531. // }];
  532. }];
  533. }
  534. - (BOOL)checkUser:(id<IMHostAble>)user
  535. {
  536. if (![user conformsToProtocol:@protocol(AVUserAble)])
  537. {
  538. return NO;
  539. }
  540. return YES;
  541. }
  542. @end