PublishVoiceViewController.m 24 KB

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