123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- //
- // CreateLiveViewController.m
- // KulexiuForTeacher
- //
- // Created by Kyle on 2022/3/30.
- //
- #import "CreateLiveViewController.h"
- #import "CreateLiveBodyView.h"
- #import "CustomNavViewController.h"
- #import "LiveRoomViewController.h"
- #import "KSChoosePicker.h"
- #import "KSMediaManager.h"
- @interface CreateLiveViewController ()
- @property (nonatomic, strong) CreateLiveBodyView *bodyView;
- @property (nonatomic, strong) NSString *chooseTime;
- @property (nonatomic, strong) KSMediaManager *mediaManager;
- @property (nonatomic, strong) NSMutableArray *imageArray; // 图片数组
- @property (nonatomic, strong) NSMutableArray *imageAsset; // 图片 asset
- @end
- @implementation CreateLiveViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- [self allocTitle:@"创建直播"];
- [self configUI];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- if ([self checkIsLoginToLoginView:YES]) {
-
- }
- }
- - (void)configUI {
- self.bodyView = [CreateLiveBodyView shareInstance];
- [self.scrollView addSubview:self.bodyView];
- CGFloat height = kScreenHeight -kNaviBarHeight - iPhoneXSafeBottomMargin > 770 ? kScreenHeight -kNaviBarHeight - iPhoneXSafeBottomMargin : 770;
- [self.bodyView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.scrollView.mas_top);
- make.left.right.mas_equalTo(self.view);
- make.height.mas_equalTo(height);
- }];
-
-
- [self.scrollView setContentSize:CGSizeMake(kScreenWidth, height)];
- MJWeakSelf;
- [self.bodyView createSureCallback:^(BOOL chooseTime, NSString * _Nonnull title, NSString * _Nonnull content) {
- if (chooseTime) {
- [weakSelf chooseTimeAction];
- }
- else {
- [weakSelf createLiveAction:title content:content];
- }
- }];
-
- [self.bodyView chooseCoverCallback:^{
- [weakSelf pushImagePickerController];
- }];
- }
- - (void)pushImagePickerController {
- // 调用相册
- self.mediaManager = [[KSMediaManager alloc] init];
- self.mediaManager.mediaType = MEDIATYPE_PHOTO;
- self.mediaManager.maxPhotoNumber = 1;
- self.mediaManager.baseCtrl = self;
- self.mediaManager.needCropImage = YES;
- MJWeakSelf;
- [self.mediaManager noAlertCallback:^(NSString * _Nullable videoUrl, NSMutableArray * _Nullable imageArray, NSMutableArray * _Nullable imageAsset) {
- [weakSelf displayChooseImage:imageArray imageAsset:imageAsset];
- }];
- [self.mediaManager pushImagePickerController];
- }
- - (void)displayChooseImage:(NSMutableArray *)imageArray imageAsset:(NSMutableArray *)imageAsset {
- // 添加图片
- self.imageArray = [imageArray mutableCopy];
- self.imageAsset = [imageAsset mutableCopy];
- // 重新布局
- [self.bodyView.coverImage setImage:[self.imageArray lastObject]];
- self.bodyView.coverBgView.hidden = NO;
- }
- - (void)chooseTimeAction {
- MJWeakSelf;
- KSChoosePicker *picker = [[KSChoosePicker alloc] initWithTitle:@"直播时长(分钟)" sourceData:@[@"30",@"45",@"60",@"90"] chooseReturnWithBlock:^(NSString * _Nonnull returnValue, NSInteger chooseIndex) {
- weakSelf.chooseTime = returnValue;
- weakSelf.bodyView.timeLabel.text = [NSString stringWithFormat:@"%@分钟",returnValue];
- } cancel:^{
- }];
- [picker showPicker];
- }
- - (void)createLiveAction:(NSString *)title content:(NSString *)content {
-
- if (self.imageArray.count == 0) {
- [self MBPShow:@"请上传直播封面图"];
- return;
- }
- [self showhud];
- UIImage *coverImage = [self.imageArray lastObject];
- NSData *imgData = [UIImage turnsImaegDataByImage:coverImage];
- NSString *fileName = @"image";
- [[KSUploadManager shareInstance] configBucketName:@"daya"];
- [[KSUploadManager shareInstance] uploadImage:imgData fileName:fileName successCallback:^(NSMutableArray * _Nonnull fileUrlArray) {
- NSString *avatarUrl = [fileUrlArray lastObject];
- [self uploadCoverImage:avatarUrl liveTilte:title content:content];
- } faliure:^(NSError * _Nullable error, NSString *descMessaeg) {
- [self removehub];
- if (![NSString isEmptyString:descMessaeg]) {
- [self MBPShow:descMessaeg];
- }
- }];
-
-
- }
- - (void)uploadCoverImage:(NSString *)coverImageUrl liveTilte:(NSString *)title content:(NSString *)content {
-
- [KSNetworkingManager liveRoomCreateTempLiveRoom:KS_POST coverPic:coverImageUrl liveRemark:content roomTitle:title liveTime:[self.chooseTime integerValue] success:^(NSDictionary * _Nonnull dic) {
- [self removehub];
- if ([dic ks_integerValueForKey:@"code"] == 200 && [dic ks_boolValueForKey:@"status"]) {
- NSString *roomId = [dic ks_stringValueForKey:@"data"];
- [self previewViewWithRoomId:roomId liveDesc:content];
- }
- else {
- [self MBPShow:MESSAGEKEY];
- }
- } faliure:^(NSError * _Nonnull error) {
- [self removehub];
- }];
- }
- - (void)previewViewWithRoomId:(NSString *)roomId liveDesc:(NSString *)liveDesc {
- LiveRoomViewController *ctrl = [[LiveRoomViewController alloc] init];
- ctrl.roomId = roomId;
- ctrl.isTempRoom = YES;
- ctrl.liveContent = liveDesc;
- MJWeakSelf;
- [ctrl backRefreshCallback:^{
- [weakSelf backAction];
- }];
- CustomNavViewController *navCtrl = [[CustomNavViewController alloc] initWithRootViewController:ctrl];
- navCtrl.modalPresentationStyle = UIModalPresentationFullScreen;
-
-
- [self.navigationController presentViewController:navCtrl animated:YES completion:nil];
- }
- #pragma mark - 懒加载
- - (NSMutableArray *)imageArray {
- if (!_imageArray) {
- _imageArray = [NSMutableArray array];
- }
- return _imageArray;
- }
- - (NSMutableArray *)imageAsset {
- if (!_imageAsset) {
- _imageAsset = [NSMutableArray array];
- }
- return _imageAsset;
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|