Commit 1dd9740b02e194524069c796f51f600a4491234c
1 parent
1d81a8e8
no message
Showing
2 changed files
with
113 additions
and
2 deletions
CNLiveBUserAgreement/Classes/CNLiveUserAgreementController.m
| @@ -9,6 +9,8 @@ | @@ -9,6 +9,8 @@ | ||
| 9 | #import "CNLiveUserAgreementController.h" | 9 | #import "CNLiveUserAgreementController.h" |
| 10 | #import "QMUIKit.h" | 10 | #import "QMUIKit.h" |
| 11 | #import "WKWebViewJavascriptBridge.h" | 11 | #import "WKWebViewJavascriptBridge.h" |
| 12 | +#import "QNUploadManager.h" | ||
| 13 | +#import "QNResponseInfo.h" | ||
| 12 | 14 | ||
| 13 | #import <AVFoundation/AVCaptureDevice.h> | 15 | #import <AVFoundation/AVCaptureDevice.h> |
| 14 | #import <AVFoundation/AVMediaFormat.h> | 16 | #import <AVFoundation/AVMediaFormat.h> |
| @@ -17,11 +19,15 @@ | @@ -17,11 +19,15 @@ | ||
| 17 | #import <CNLiveRequestBastKit/CNLiveNetworking.h> | 19 | #import <CNLiveRequestBastKit/CNLiveNetworking.h> |
| 18 | #import "CNLiveManager.h" | 20 | #import "CNLiveManager.h" |
| 19 | #import "CNLiveEnvironment.h" | 21 | #import "CNLiveEnvironment.h" |
| 22 | +#import "CNLiveBusinessTools.h" | ||
| 23 | +#import "CNLiveTimeTools.h" | ||
| 24 | +#import "CNLiveCommonCategory.h" | ||
| 20 | 25 | ||
| 21 | #import "CNLiveWebView.h" | 26 | #import "CNLiveWebView.h" |
| 22 | 27 | ||
| 23 | @interface CNLiveUserAgreementController ()<UIImagePickerControllerDelegate,UINavigationControllerDelegate,TZImagePickerControllerDelegate> | 28 | @interface CNLiveUserAgreementController ()<UIImagePickerControllerDelegate,UINavigationControllerDelegate,TZImagePickerControllerDelegate> |
| 24 | @property (nonatomic, strong) NSMutableArray *images; | 29 | @property (nonatomic, strong) NSMutableArray *images; |
| 30 | +@property (nonatomic, strong) NSMutableArray *pics; | ||
| 25 | 31 | ||
| 26 | @end | 32 | @end |
| 27 | 33 | ||
| @@ -226,7 +232,7 @@ | @@ -226,7 +232,7 @@ | ||
| 226 | NSMutableDictionary *data = [NSMutableDictionary dictionaryWithDictionary:responseObject[@"data"]]; | 232 | NSMutableDictionary *data = [NSMutableDictionary dictionaryWithDictionary:responseObject[@"data"]]; |
| 227 | NSDictionary *dic = (NSDictionary *)data; | 233 | NSDictionary *dic = (NSDictionary *)data; |
| 228 | if (!error && dic[@"token"]) { | 234 | if (!error && dic[@"token"]) { |
| 229 | - // [self QNStartUploadWithtoken:dic[@"token"]]; | 235 | + [self QNStartUploadWithtoken:dic[@"token"]]; |
| 230 | }else { | 236 | }else { |
| 231 | [QMUITips hideAllToastInView:self.view animated:YES]; | 237 | [QMUITips hideAllToastInView:self.view animated:YES]; |
| 232 | [QMUITips showError:error.localizedDescription inView:self.view hideAfterDelay:1.5]; | 238 | [QMUITips showError:error.localizedDescription inView:self.view hideAfterDelay:1.5]; |
| @@ -234,4 +240,109 @@ | @@ -234,4 +240,109 @@ | ||
| 234 | }]; | 240 | }]; |
| 235 | } | 241 | } |
| 236 | 242 | ||
| 243 | +// 图片开始上传 | ||
| 244 | +- (void)QNStartUploadWithtoken:(NSString *)token { | ||
| 245 | + __weak typeof(self) weakSelf = self; | ||
| 246 | + // 图片视频压缩(LXG) | ||
| 247 | + [_images enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { | ||
| 248 | + if (!weakSelf.images[idx]) { | ||
| 249 | + [QMUITips hideAllToastInView:self.view animated:YES]; | ||
| 250 | + [QMUITips showError:@"提交失败" inView:self.view hideAfterDelay:1.5]; | ||
| 251 | + return; | ||
| 252 | + } | ||
| 253 | + NSData *zipData = [UIImage zipNSDataWithImage:weakSelf.images[idx]];//非原图压缩 | ||
| 254 | + if (zipData.length > 20*1024.0*1024.0) {//压缩后大于20M | ||
| 255 | + [QMUITips hideAllToastInView:self.view animated:YES]; | ||
| 256 | + [QMUITips showError:@"图片过大" inView:self.view hideAfterDelay:1.5]; | ||
| 257 | + return; | ||
| 258 | + }else{ | ||
| 259 | + weakSelf.images[idx] = [UIImage imageWithData:zipData]; | ||
| 260 | + } | ||
| 261 | + | ||
| 262 | + }]; | ||
| 263 | + | ||
| 264 | + NSMutableDictionary *picDict = [NSMutableDictionary dictionaryWithCapacity:_images.count]; | ||
| 265 | + NSMutableArray *keyArr = [NSMutableArray arrayWithCapacity:_images.count]; | ||
| 266 | + self.pics = [NSMutableArray arrayWithCapacity:_images.count]; | ||
| 267 | + for (int i = 0; i < _images.count; i++) { | ||
| 268 | + @autoreleasepool { | ||
| 269 | + UIImage *image = _images[i]; | ||
| 270 | + __block NSData *imageData1 = UIImageJPEGRepresentation(image, 1); | ||
| 271 | + NSString *timeTampStr = [CNLiveTimeTools get13tsRandTimeStr]; | ||
| 272 | + // NSString *mineType = @"image/jpeg"; | ||
| 273 | + NSString *qiniuFileName; | ||
| 274 | + qiniuFileName = [NSString stringWithFormat:@"%@/%@.jpg",[self getImageBuketkeyFromServerWithExt], timeTampStr]; | ||
| 275 | + QNUploadManager *uploadManager = [QNUploadManager sharedInstanceWithConfiguration:nil]; | ||
| 276 | + [uploadManager putData:imageData1 key:qiniuFileName token:token complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) { | ||
| 277 | + if (info.ok) { | ||
| 278 | + NSString *imageUrl = [NSString stringWithFormat:@"%@%@",API_PhotoUrl,key]; | ||
| 279 | + [picDict setObject:imageUrl ? imageUrl: @"" forKey:@"imageUrl"]; | ||
| 280 | + [picDict setObject:[NSString stringWithFormat:@"%.0f",image.size.width] forKey:@"imageWidth"]; | ||
| 281 | + [picDict setObject:[NSString stringWithFormat:@"%.0f",image.size.height] forKey:@"imageHeight"]; | ||
| 282 | + [keyArr addObject:key]; | ||
| 283 | + NSMutableDictionary *dict = [[NSMutableDictionary alloc]initWithDictionary:picDict]; | ||
| 284 | + [self.pics addObject:dict]; | ||
| 285 | + | ||
| 286 | + if (keyArr.count == weakSelf.images.count) { | ||
| 287 | + id imagesArrData = @{ @"images": self.pics.copy }; | ||
| 288 | + [weakSelf.images removeAllObjects]; | ||
| 289 | + // 帮助与反馈->产品建议App->h5图片urls | ||
| 290 | + [self.bridge callHandler:wjjSubmitSuccess data:imagesArrData responseCallback:^(id responseData) { | ||
| 291 | + NSLog(@"ObjC received response: %@", responseData); | ||
| 292 | + }]; | ||
| 293 | + } | ||
| 294 | + } else if (info.broken) { | ||
| 295 | + [QMUITips hideAllToastInView:self.view animated:YES]; | ||
| 296 | + [QMUITips showError:@"网络连接已断开" inView:self.view hideAfterDelay:1.5]; | ||
| 297 | + return ; | ||
| 298 | + } else { | ||
| 299 | + [QMUITips hideAllToastInView:self.view animated:YES]; | ||
| 300 | + [QMUITips showError:info.error.localizedDescription inView:self.view hideAfterDelay:1.5]; | ||
| 301 | + return ; | ||
| 302 | + } | ||
| 303 | + } option:nil]; | ||
| 304 | + } | ||
| 305 | + } | ||
| 306 | + | ||
| 307 | +} | ||
| 308 | + | ||
| 309 | +// 图片转成base64字符串需要先取出所有空格和换行符 | ||
| 310 | +- (NSString *)removeSpaceAndNewline:(NSString *)str{ | ||
| 311 | + NSString *temp = [str stringByReplacingOccurrencesOfString:@" " withString:@""]; | ||
| 312 | + temp = [temp stringByReplacingOccurrencesOfString:@"\r" withString:@""]; | ||
| 313 | + temp = [temp stringByReplacingOccurrencesOfString:@"\n" withString:@""]; | ||
| 314 | + return temp; | ||
| 315 | +} | ||
| 316 | + | ||
| 317 | +// 图片的BucketKey,BuketKey为文件路径 | ||
| 318 | +- (NSString *)getImageBuketkeyFromServerWithExt{ | ||
| 319 | + NSString *spid = [CNLiveBusinessTools getSpid]; | ||
| 320 | + NSString *imgBucketKey = [NSString stringWithFormat:@"%@/img", spid]; | ||
| 321 | + NSString *yearTime = [CNLiveTimeTools getyyMMdd]; | ||
| 322 | + NSString *bucketKey = [NSString stringWithFormat:@"%@/%@",imgBucketKey,yearTime]; | ||
| 323 | + return bucketKey; | ||
| 324 | + | ||
| 325 | +} | ||
| 326 | + | ||
| 327 | +- (NSData *)image_TransForm_Data:(UIImage *)image{ | ||
| 328 | + NSData *imageData = UIImageJPEGRepresentation(image, 0.5); | ||
| 329 | + //几乎是按0.5图片大小就降到原来的一半 | ||
| 330 | + return imageData; | ||
| 331 | +} | ||
| 332 | + | ||
| 333 | +//压缩图片质量 | ||
| 334 | +-(UIImage *)reduceImage:(UIImage *)image percent:(float)percent{ | ||
| 335 | + NSData *imageData = UIImageJPEGRepresentation(image, percent); | ||
| 336 | + UIImage *newImage = [UIImage imageWithData:imageData]; | ||
| 337 | + return newImage; | ||
| 338 | +} | ||
| 339 | +//压缩图片尺寸 | ||
| 340 | +- (UIImage*)imageWithImageSimple:(UIImage*)image scaledToSize:(CGSize)newSize{ | ||
| 341 | + UIGraphicsBeginImageContext(newSize); | ||
| 342 | + [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)]; | ||
| 343 | + UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext(); | ||
| 344 | + UIGraphicsEndImageContext(); | ||
| 345 | + return newImage; | ||
| 346 | +} | ||
| 347 | + | ||
| 237 | @end | 348 | @end |
Example/CNLiveBUserAgreement/CNLIVEViewController.m
| @@ -32,7 +32,7 @@ | @@ -32,7 +32,7 @@ | ||
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | - (void)testButtonClicked { | 34 | - (void)testButtonClicked { |
| 35 | - [CNLiveUserAgreementManager jumpToAgreementH5WithType:CNLiveUserAgreementComplaints]; | 35 | + [CNLiveUserAgreementManager jumpToAgreementH5WithType:CNLiveUserAgreementHelp]; |
| 36 | 36 | ||
| 37 | } | 37 | } |
| 38 | 38 |