CNLiveViewController.m
7.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
//
// 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;
imagePickerVc.maxVideoDuration = kChat_limit_video_length;
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];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end