CNLiveViewController.m 8.01 KB
//
//  CNLiveViewController.m
//  CNLiveImagePickerController
//
//  Created by jyyjkt on 08/01/2019.
//  Copyright (c) 2019 jyyjkt. All rights reserved.
//

#import "CNLiveViewController.h"
#import "CNImagePickerManager.h"
#import <CNLiveUploadManager/CNLiveUploadManager.h>

@interface CNLiveViewController ()<TZImagePickerControllerDelegate>

@end

@implementation CNLiveViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    UIButton *button  = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:button];
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    button.backgroundColor = [UIColor yellowColor];
    button.frame = CGRectMake(50, 50, 100, 100);
    [button setTitle:@"相册" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    
    
}

- (void)buttonAction:(UIButton *)sender {
    
//    [CNImagePickerManager ImagePickerWithMaxImagesCount:9 columnNumber:4 delegate:self pushPhotoPickerVc:YES isSelectOriginalPhoto:nil selectedAssets:nil enterType:CNImagePickerEnterTypeFriendsCircle pickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
//
//    }];
//
//     CNImagePickerController *imagePickerVc = [[CNImagePickerController alloc]initWithMaxImagesCount:9 columnNumber:4 delegate:self pushPhotoPickerVc:YES];
//        [imagePickerVc configTZImagePicker];//配置
//        imagePickerVc.modalPresentationStyle = UIModalPresentationFullScreen;
//        imagePickerVc.isSelectOriginalPhoto = NO;//是否选择原图
//        // 1.设置目前已经选中的图片数组
//        imagePickerVc.selectedAssets = nil; // 目前已经选中的图片数组
//        // 发布时长限制
//        imagePickerVc.maxEditVideoTime = kChat_limit_video_length_upload;
//        imagePickerVc.maxVideoDuration = kChat_limit_video_length_upload;
//        imagePickerVc.conversationId = @"defult";
//        imagePickerVc.timeout = 300;
//        imagePickerVc.isExportVideo = YES;//允许导出
//        /// 5. Single selection mode, valid when maxImagesCount = 1
//        /// 5. 单选模式,maxImagesCount为1时才生效
//        // 设置竖屏下的裁剪尺寸
//        NSInteger left = 30;
//        NSInteger widthHeight = self.view.width - 2 * left;
//        NSInteger top = (self.view.height - widthHeight) / 2;
//        imagePickerVc.cropRect = CGRectMake(left, top, widthHeight, widthHeight);
//
//        // You can get the photos by block, the same as by delegate.
//        // 你可以通过block或者代理,来得到用户选择的照片.
//        __weak typeof(self) weakSelf = self;
//        [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
//
//        }];
//        [imagePickerVc setImagePickerControllerDidCancelHandle:^{
//
//
//        }];
//        [imagePickerVc setDidNewFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray<TZAssetModel *> *models, NSArray *assets, BOOL isSelectOriginalPhoto) {
//            NSLog(@"输出models = %@",models);
//    //
//            NSMutableArray *operationArray = [NSMutableArray new];
//            for (int i = 0; i < photos.count;i++ ) {
//
//                NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlock:^{
//                    UIImage *img = photos[i];
//                    TZAssetModel *model = models[i];
//
//                    //进行图片视频压缩(LXG)
//                    if (model.type == TZAssetModelMediaTypeVideo)
//                    {//视频
//                        NSError *err = nil;
//                        if (!model.exportURL) {
//                            NSLog(@"///////导出失败");
//                            return;
//                        }
//                        NSData* data = [NSData dataWithContentsOfURL:model.exportURL options:NSDataReadingMappedIfSafe error:&err];
//
//                        NSLog(@"已经导出视频");
//
//
//                    }else
//                    {
//
//                        if ([CNLiveBusinessTools isGif:assets[i]]) {
//                            img.isGif = @"1";
//                            PHImageManager *imageManager = [PHImageManager defaultManager];
//                            PHImageRequestOptions *options = [PHImageRequestOptions new];
//                            options.deliveryMode =  PHImageRequestOptionsDeliveryModeFastFormat;
//                            options.resizeMode = PHImageRequestOptionsResizeModeNone;
//    //                        options.networkAccessAllowed = YES;
//                            [imageManager requestImageDataForAsset:assets[i] options:options resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
//                                img.imageData = imageData;
//                                if (imageData.length > kChat_limit_photo_upload) {
//                                  dispatch_async(dispatch_get_main_queue(), ^{
//
//                                      NSLog(@"图片过大");
//                                       });
//                                }
//                                else{
//                                    NSLog(@"发送图片");
//                                }
//
//                            }];
//                        }
//                        else
//                        {
//
//                        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//                            // 进行图片压缩(LXG)
//                            NSData *zipData = nil;
//                            if (isSelectOriginalPhoto) {//是否原图
//                                zipData = [UIImage zipNSDataWithImage:img isOriginal:YES];//原图压缩
//
//                            }else{
//                                //zipNSDataWithImage
//                                zipData = [UIImage zipNSDataWithImage:img];//非原图压缩1028
//                            }
//
//                            if (zipData.length > kChat_limit_photo_upload) {//压缩后大于20M
//                                dispatch_async(dispatch_get_main_queue(), ^{
//                                    if (isSelectOriginalPhoto) {
//                                        NSLog(@"发送的原图过大");
//                                    }else{
//                                         NSLog(@"发送的图过大");
//                                    }
//                                });
//                            }
//                            else{
//                                NSLog(@"发送图片");
//                            }
//
//                        });
//
//                        }
//
//                    }
//                }];
//
//                [operationArray addObject:operation];
//
//            }
//
//
//        }];
//
//        [self presentViewController:imagePickerVc animated:YES completion:nil];
    
    
    
    CNImagePickerController *imagePickerVc = [[CNImagePickerController alloc] initWithMaxImagesCount:9 delegate:self];
    imagePickerVc.modalPresentationStyle = UIModalPresentationFullScreen;
    imagePickerVc.allowTakePicture = NO; // 在内部显示拍照按钮
    imagePickerVc.allowPreview = NO;
    imagePickerVc.allowPickingOriginalPhoto = NO;
    imagePickerVc.allowPickingVideo = YES;
    
    [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
        UIImage *image = photos.firstObject;
        if (image) {
            
            NSLog(@"发送的图过大 = %@",image);
        }
        
        
        
    }];
    [self presentViewController:imagePickerVc animated:YES completion:nil];
    
    
    
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end