Files
yinmeng-ios-store/yinmeng-ios/DingDangApp/CodeClass/MyInfo/CC/DDMyInfoReportViewController.m

554 lines
27 KiB
Mathematica
Raw Normal View History

2023-12-07 10:50:21 +08:00
//
// DDMyInfoReportViewController.m
// DingDangApp
//
// Created by apple on 2023/7/5.
//
#import "DDMyInfoReportViewController.h"
#import <IQKeyboardManager/IQKeyboardManager.h>
#import "ZLPhotoActionSheet.h"
#import "ZLPhotoManager.h"
#import "FileToolsObject.h"
#import "UITextView+Placeholder.h"
@interface DDMyInfoReportViewController ()<UITextViewDelegate>
@property (nonatomic, strong) ZLPhotoActionSheet * photoActionSheet;
@property (nonatomic,strong) UIButton * recordSelectTypeButton;
@property (nonatomic,strong) UIScrollView * baseScrollView;
@property (nonatomic,strong) UIView * typeView;
@property (nonatomic,strong) UITextView * textView;
@property (nonatomic,strong) UILabel * countLabel;
@property (nonatomic,strong) UIView * selectImageView;
@property (nonatomic,strong) UIView * bottomView;
@property (nonatomic,strong) UIButton * commitButton;
@property (nonatomic,strong) UITapGestureRecognizer * tapGes;
@property (nonatomic,strong) UIButton * leftButton;
@property (nonatomic,strong) NSMutableArray * titleArray;
@property (nonatomic,strong) NSMutableArray * imagesArray;
@property (nonatomic,copy) NSString *uploadType;
@property (nonatomic,copy) NSString *VideofileUrl;
@property (nonatomic,copy) NSString *ReleaseVideoUrl;
@end
@implementation DDMyInfoReportViewController
- (UIScrollView *)baseScrollView{
if (!_baseScrollView){
_baseScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, self.customNavBar.bottom, kWidth, kHeight - self.customNavBar.bottom)];
WeakSelf(weakSelf)
[_baseScrollView jk_addTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
[weakSelf.view endEditing:YES];
}];
}return _baseScrollView;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self defaultNavTitle:@"举报" hideLine:NO];
self.view.backgroundColor = [UIColor whiteColor];
if (self.isSmallMessage){
[self.customNavBar wr_setLeftButtonWithImage:[UIImage imageNamed:@"com_3"]];
WeakSelf(weakSelf)
self.customNavBar.onClickLeftButton = ^{
[weakSelf dismissViewControllerAnimated:YES completion:^{}];
};
}
[self.view addSubview:self.baseScrollView];
[self requestTypeData];
}
- (void)requestTypeData {
[self questionTypeView];
[self descriptionView];
[self addImageView];
}
- (void)questionTypeView {
int line = self.titleArray.count%4 > 0 ? (int)(self.titleArray.count/4+1) : (int)self.titleArray.count/4;
float typeViewHeight = 47.5 + line * (30 + 15) + 15;
_typeView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kWidth, typeViewHeight)];
[self.baseScrollView addSubview:self.typeView];
UILabel * titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 15, kWidth, 22.5)];
titleLabel.font = [UIFont boldSystemFontOfSize:16];
titleLabel.textColor = [UIColor jk_colorWithHexString:@"#333333"];
[self.typeView addSubview:titleLabel];
NSMutableAttributedString * attriTitle = [NSMutableAttributedString new];
NSString * leftString = @"举报原因";
NSString * rightString = @"(必填)";
[attriTitle appendAttributedString:[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@%@",leftString,rightString] attributes:nil]];
[attriTitle yy_setFont:[UIFont boldSystemFontOfSize:16] range:NSMakeRange(0, leftString.length)];
[attriTitle yy_setColor:[UIColor jk_colorWithHexString:@"#333333"] range:NSMakeRange(0, leftString.length)];
[attriTitle yy_setFont:[UIFont systemFontOfSize:13] range:NSMakeRange(leftString.length, rightString.length)];
[attriTitle yy_setColor:[UIColor jk_colorWithHexString:@"#999999"] range:NSMakeRange(leftString.length, rightString.length)];
titleLabel.attributedText = attriTitle;
int distance = 15;
float buttonWidth = (kWidth - distance * 2 - distance * 3)/4;
for (int a = 0; a < self.titleArray.count; a ++) {
UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(distance * (a%4 + 1) + buttonWidth * (a%4) ,
titleLabel.bottom + distance + a/4 * (30 + distance),
buttonWidth,30);
[button setTitle:self.titleArray[a] forState:UIControlStateNormal];
[button setTitleColor:[UIColor jk_colorWithHexString:@"#333333"] forState:UIControlStateNormal];
[button setTitleColor:UIColor.whiteColor forState:UIControlStateSelected];
[button setBackgroundImage:[UIImage imageNamed:@"myinfo_77"] forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage imageNamed:@"myinfo_78"] forState:UIControlStateSelected];
button.titleLabel.font = [UIFont systemFontOfSize:14];
button.tag = a;
button.layer.masksToBounds = YES;
button.layer.cornerRadius = 15;
[self.typeView addSubview:button];
[button addTarget:self action:@selector(titleButtonClick:) forControlEvents:UIControlEventTouchUpInside];
}
}
- (void)titleButtonClick:(UIButton *)sender{
self.recordSelectTypeButton.selected = NO;
sender.selected =YES;
self.recordSelectTypeButton = sender;
}
- (void)descriptionView {
UILabel * titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, self.typeView.bottom + 15, kWidth - 30, 23)];
titleLabel.font = [UIFont boldSystemFontOfSize:16];
titleLabel.textColor = [UIColor jk_colorWithHexString:@"#333333"];
[self.baseScrollView addSubview:titleLabel];
NSMutableAttributedString * attriTitle = [NSMutableAttributedString new];
NSString * leftString = @"举报描述";
NSString * rightString = @"(选填)";
[attriTitle appendAttributedString:[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@%@",leftString,rightString] attributes:nil]];
[attriTitle yy_setFont:[UIFont boldSystemFontOfSize:16] range:NSMakeRange(0, leftString.length)];
[attriTitle yy_setColor:[UIColor jk_colorWithHexString:@"#333333"] range:NSMakeRange(0, leftString.length)];
[attriTitle yy_setFont:[UIFont systemFontOfSize:13] range:NSMakeRange(leftString.length, rightString.length)];
[attriTitle yy_setColor:[UIColor jk_colorWithHexString:@"#999999"] range:NSMakeRange(leftString.length, rightString.length)];
titleLabel.attributedText = attriTitle;
_textView = [[UITextView alloc] initWithFrame:CGRectMake(15, titleLabel.bottom + 10, kWidth - 30, 100)];
_textView.textColor = [UIColor jk_colorWithHexString:@"#333333"];
self.textView.placeholder = @"请描述带有对方昵称和事情的简要经过~";
[self.textView roundCorners:UIRectCornerAllCorners radius:6];
self.textView.delegate = self;
self.textView.backgroundColor = [UIColor jk_colorWithHexString:@"#F6F6F6"];
self.textView.font = [UIFont systemFontOfSize:14];
[self.baseScrollView addSubview:self.textView];
_countLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.textView.width - 100 - 12, self.textView.height - 20 - 12, 100, 20)];
self.countLabel.text = @"0/100";
self.countLabel.textColor = [UIColor jk_colorWithHexString:@"666666"];
self.countLabel.textAlignment = NSTextAlignmentRight;
self.textView.font = [UIFont systemFontOfSize:14];
[self.textView addSubview:self.countLabel];
@weakify(self);
[RACObserve(self, textView.text) subscribeNext:^(id _Nullable x) {
@strongify(self);
self.countLabel.text = [NSString stringWithFormat:@"%ld/100",self.textView.text.length];
}];
}
- (void)addImageView {
UILabel * titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, self.textView.bottom + 30, kWidth - 30, 23)];
titleLabel.font = [UIFont boldSystemFontOfSize:16];
titleLabel.textColor = [UIColor jk_colorWithHexString:@"#333333"];
[self.baseScrollView addSubview:titleLabel];
NSMutableAttributedString * attriTitle = [NSMutableAttributedString new];
NSString * leftString = @"凭证";
NSString * rightString = @"选填可添加3张图片证据或1个视频证据";
[attriTitle appendAttributedString:[[NSAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@%@",leftString,rightString] attributes:nil]];
[attriTitle yy_setFont:[UIFont boldSystemFontOfSize:16] range:NSMakeRange(0, leftString.length)];
[attriTitle yy_setColor:[UIColor jk_colorWithHexString:@"#333333"] range:NSMakeRange(0, leftString.length)];
[attriTitle yy_setFont:[UIFont systemFontOfSize:13] range:NSMakeRange(leftString.length, rightString.length)];
[attriTitle yy_setColor:[UIColor jk_colorWithHexString:@"#999999"] range:NSMakeRange(leftString.length, rightString.length)];
titleLabel.attributedText = attriTitle;
_selectImageView = [[UIView alloc] initWithFrame:CGRectMake(0, titleLabel.bottom, kWidth, 125)];
[self.baseScrollView addSubview:self.selectImageView];
_bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, kHeight - 10 - DDBottomHeight() - 44, kWidth, 60+DDBottomHeight())];
_bottomView.backgroundColor = UIColor.whiteColor;
[self.view addSubview:self.bottomView];
_commitButton = [UIButton buttonWithType:UIButtonTypeCustom];
[self.commitButton setTitle:@"提交" forState:UIControlStateNormal];
UIEdgeInsets edge = UIEdgeInsetsMake(10, 10, 10, 10);
UIImage * frameImg1 = [UIImage imageNamed:@"com_7"];
frameImg1 = [frameImg1 resizableImageWithCapInsets:edge resizingMode:UIImageResizingModeStretch];
UIImage * frameImg2 = [UIImage imageNamed:@"com_6"];
frameImg2 = [frameImg2 resizableImageWithCapInsets:edge resizingMode:UIImageResizingModeStretch];
[self.commitButton setBackgroundImage:frameImg1 forState:UIControlStateNormal];
[self.commitButton setBackgroundImage:frameImg2 forState:UIControlStateSelected];
[self.commitButton setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
self.commitButton.titleLabel.font = [UIFont systemFontOfSize:17];
self.commitButton.frame = CGRectMake(37.5, 0, kWidth - 65, 44);
@weakify(self);
[[self.commitButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
@strongify(self);
[self commitButtonClick];
}];
[self.bottomView addSubview:self.commitButton];
self.baseScrollView.contentSize = CGSizeMake(kWidth, self.selectImageView.bottom + 10);
[self reloadImagesViewUI];
RAC(self.commitButton,selected) =
RAC(self.commitButton,enabled) = [RACSignal combineLatest:@[RACObserve(self,recordSelectTypeButton.tag)] reduce:^id _Nonnull(NSInteger tag) {
return @(tag!=0);
}];
}
- (void)reloadImagesViewUI {
if ([self.uploadType isEqualToString:@"img"]) {
[self.selectImageView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
[[self mutableArrayValueForKey:@"imagesArray"] removeObject:[UIImage imageNamed:@"myinfo_43"]];
if (self.imagesArray.count < 3) {
[[self mutableArrayValueForKey:@"imagesArray"] addObject:[UIImage imageNamed:@"myinfo_43"]];
}
for (int a = 0; a < self.imagesArray.count; a ++) {
UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(15 + 105 * a + (self.selectImageView.width - 105 * 3 - 30)/2*a, 20, 105, 105)];
imageView.image = self.imagesArray[a];
[imageView roundCorners:UIRectCornerAllCorners radius:6];
[self.selectImageView addSubview:imageView];
if (self.imagesArray[a] == [UIImage imageNamed:@"myinfo_43"]) {
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] init];
@weakify(self);
[[tap rac_gestureSignal] subscribeNext:^(__kindof UIGestureRecognizer * _Nullable x) {
@strongify(self);
[self selectImage];
}];
imageView.userInteractionEnabled = YES;
[imageView addGestureRecognizer:tap];
continue;
}
UIButton * deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
[deleteButton setImage:[UIImage imageNamed:@"myinfo_42"] forState:UIControlStateNormal];
deleteButton.frame = CGRectMake(imageView.right - 22, 0, 44, 44);
deleteButton.tag = a;
@weakify(self);
[[deleteButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
@strongify(self);
[[self mutableArrayValueForKey:@"imagesArray"] removeObjectAtIndex:x.tag];
[self reloadImagesViewUI];
}];
[self.selectImageView addSubview:deleteButton];
}
}else{
dispatch_async(dispatch_get_main_queue(), ^{
[self.selectImageView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
[[self mutableArrayValueForKey:@"imagesArray"] removeObject:[UIImage imageNamed:@"myinfo_43"]];
if (self.imagesArray.count < 1) {
[[self mutableArrayValueForKey:@"imagesArray"] addObject:[UIImage imageNamed:@"myinfo_43"]];
}
for (int a = 0; a < self.imagesArray.count; a ++) {
UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(15 + 105 * a + (self.selectImageView.width - 105 * 3 - 30)/2*a, 20, 105, 105)];
imageView.image = self.imagesArray[a];
[imageView roundCorners:UIRectCornerAllCorners radius:6];
[self.selectImageView addSubview:imageView];
if (self.imagesArray[a] == [UIImage imageNamed:@"myinfo_43"]) {
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] init];
@weakify(self);
[[tap rac_gestureSignal] subscribeNext:^(__kindof UIGestureRecognizer * _Nullable x) {
@strongify(self);
[self selectImage];
}];
imageView.userInteractionEnabled = YES;
[imageView addGestureRecognizer:tap];
continue;
}
UIButton * playButton = [UIButton buttonWithType:UIButtonTypeCustom];
[playButton setImage:[UIImage imageNamed:@"com_5"] forState:UIControlStateNormal];
playButton.frame = CGRectMake(0, 0, 24, 24);
playButton.center = imageView.center;
[[playButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
}];
[self.selectImageView addSubview:playButton];
UIButton * deleteButton = [UIButton buttonWithType:UIButtonTypeCustom];
[deleteButton setImage:[UIImage imageNamed:@"myinfo_42"] forState:UIControlStateNormal];
deleteButton.frame = CGRectMake(imageView.right - 22, 0, 44, 44);
deleteButton.tag = a;
@weakify(self);
[[deleteButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
@strongify(self);
[[self mutableArrayValueForKey:@"imagesArray"] removeObjectAtIndex:x.tag];
[self reloadImagesViewUI];
}];
[self.selectImageView addSubview:deleteButton];
}
});
}
}
- (void)selectImage {
if ([ToolsObject IsNullWithObject:self.uploadType] || self.imagesArray[0] == [UIImage imageNamed:@"myinfo_43"]) {
self.photoActionSheet.configuration.allowSelectImage = YES;
self.photoActionSheet.configuration.allowSelectVideo = YES;
self.photoActionSheet.configuration.maxSelectCount = 3;
self.photoActionSheet.configuration.mutuallyExclusiveSelectInMix = YES;
[self.photoActionSheet showPhotoLibrary];
}else{
if ([self.uploadType isEqualToString:@"img"]) {
int count = 3 - (int)(self.imagesArray.count - 1);
self.photoActionSheet.configuration.allowTakePhotoInLibrary = NO;
self.photoActionSheet.configuration.maxSelectCount = count;
self.photoActionSheet.configuration.allowSelectImage = YES;
self.photoActionSheet.configuration.allowSelectVideo = NO;
[self.photoActionSheet showPhotoLibrary];
}else{
self.photoActionSheet.configuration.allowTakePhotoInLibrary = NO;
self.photoActionSheet.configuration.allowSelectImage = NO;
self.photoActionSheet.configuration.allowSelectVideo = YES;
self.photoActionSheet.configuration.maxVideoDuration = 30.0f;
self.photoActionSheet.configuration.maxSelectCount = 1;
[self.photoActionSheet showPhotoLibrary];
}
}
@weakify(self);
[self.photoActionSheet setSelectImageBlock:^(NSArray<UIImage *> * _Nonnull images, NSArray<PHAsset *> * _Nonnull assets, BOOL isOriginal) {
@strongify(self)
[self uploadImg:assets andimage:images];
}];
}
- (void)commitButtonClick {
2023-12-13 17:56:01 +08:00
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[DDHUDManager dd_showErrorWithText:@"举报成功"];
[self.navigationController popViewControllerAnimated:YES];
});
return;
2023-12-07 10:50:21 +08:00
if ([ToolsObject IsNullWithObject:self.uploadType]|| self.imagesArray[0] == [UIImage imageNamed:@"myinfo_43"]) {
[self commitDataWithImages:@""];
return;
}
if ([self.uploadType isEqualToString:@"img"]) {
NSString *path = [FileToolsObject libraryDir];
NSMutableArray *arr = @[].mutableCopy;
for (UIImage * image in self.imagesArray) {
if (image == [UIImage imageNamed:@"myinfo_43"]) {
continue;
}
NSString * imgUrl = [NSString stringWithFormat:@"source/report/image/%@.jpg",[ToolsObject dateChangeRealtimestamp]];
[FileToolsObject createFileAtPath:[path stringByAppendingPathComponent:imgUrl] overwrite:YES];
NSData *thumbImageData = [ToolsObject compressWithMaxLength:1024 WithImage:image];
[arr addObject:[path stringByAppendingPathComponent:imgUrl]];
[FileToolsObject writeFileAtPath:[path stringByAppendingPathComponent:imgUrl] content:thumbImageData];
}
@weakify(self);
[ToolsObject uploadImageWithArr:arr WithRecourseType:OSSUploadType_ReportImage completionHandler:^(NSMutableArray * _Nonnull urlArr) {
@strongify(self);
if (urlArr.count > 0) {
__block NSString * imagesStr = @"";
[urlArr enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if (idx == 0) {
imagesStr = [NSString stringWithFormat:@"%@",obj];
return;
}
imagesStr = [NSString stringWithFormat:@"%@,%@",imagesStr,obj];
}];
dispatch_async(dispatch_get_main_queue(), ^{
[self commitDataWithImages:imagesStr];
});
return;
}
[self.view jk_makeToast:@"上传失败,请重试"];
}];
return;
}
if ([self.uploadType isEqualToString:@"video"]) {
@weakify(self);
[ToolsObject uploadVideoWithFileUrl:self.VideofileUrl WithRecourseType:OSSUploadType_ReportVideo completionHandler:^(id _Nonnull urlString) {
@strongify(self);
self.ReleaseVideoUrl = urlString;
[self commitDataWithImages:self.ReleaseVideoUrl];
return;
}];
return;
}
}
- (void)commitDataWithImages:(NSString *)images {
NSMutableDictionary * requestDict = [NSMutableDictionary dictionaryWithCapacity:0];
[requestDict setValue:@(self.juBaoType) forKey:@"scene"];
[requestDict setValue:self.jubao_id forKey:@"params"];
[requestDict setValue:self.titleArray[self.recordSelectTypeButton.tag] forKey:@"report_type"];
[requestDict setValue:self.textView.text forKey:@"report_desc"];
[requestDict setValue:images forKey:@"report_img"];
WeakSelf(weakSelf)
/// /room/report
NSString *url = [DDEncryptManager dd_aesDecryptWithText:@"FsKVcXsP8WRb7QpBRRo2DA=="];
[NetworkRequest requestPOST:url parameters:requestDict block:^(BaseResponse * _Nonnull response) {
2023-12-07 10:50:21 +08:00
[ToolsObject DismissSVProgressHUD];
if (response.code == 200){
[ToolsObject addPopVieToText:@"举报成功"];
[weakSelf.navigationController popViewControllerAnimated:YES];
}
}];
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
NSString *str = [NSString stringWithFormat:@"%@%@", textView.text, text];
if (str.length > 100) {
return NO;
}
return YES;
}
- (void)textViewDidChange:(UITextView *)textView{
self.countLabel.text = [NSString stringWithFormat:@"%lu/100",[textView.text length]];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[self.view endEditing:YES];
}
- (NSMutableArray *)imagesArray {
if (!_imagesArray) {
_imagesArray = [NSMutableArray arrayWithCapacity:0];
}
return _imagesArray;
}
- (NSMutableArray *)titleArray {
if (!_titleArray) {
_titleArray = @[@"辱骂",@"涉黄",@"涉政",@"暴力",@"广告",@"赌博",@"诈骗",@"涉毒",@"挖人",@"其他"
].mutableCopy;
}
return _titleArray;
}
-(ZLPhotoActionSheet *)photoActionSheet
{
if (!_photoActionSheet) {
_photoActionSheet = [[ZLPhotoActionSheet alloc] init];
_photoActionSheet.configuration.allowSelectImage = YES;
_photoActionSheet.configuration.allowSelectVideo = YES;
_photoActionSheet.configuration.maxSelectCount = 3;
_photoActionSheet.configuration.mutuallyExclusiveSelectInMix = YES;
_photoActionSheet.configuration.bottomBtnsNormalBgColor = [UIColor jk_colorWithHexString:@"#A739FE"];
_photoActionSheet.configuration.bottomBtnsDisableBgColor = [UIColor jk_colorWithHexString:@"#A739FE"];
_photoActionSheet.configuration.indexLabelBgColor = [UIColor jk_colorWithHexString:@"#A739FE"];
_photoActionSheet.configuration.maxVideoDuration = 30.0f;
_photoActionSheet.sender = self;
_photoActionSheet.cancleBlock = ^{};
}
return _photoActionSheet;
}
-(void)uploadImg:(NSArray *)image andimage:(NSArray *)imageArr{
PHAsset *asset = image[0];
if (asset.mediaType == PHAssetMediaTypeVideo) {
self.uploadType = @"video";
if (imageArr.count != 0) {
for (UIImage *images in imageArr) {
[[self mutableArrayValueForKey:@"imagesArray"] removeObject:[UIImage imageNamed:@"myinfo_43"]];
[[self mutableArrayValueForKey:@"imagesArray"] addObjectsFromArray:@[images]];
}
}
PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
options.version = PHImageRequestOptionsVersionCurrent;
options.deliveryMode = PHVideoRequestOptionsDeliveryModeAutomatic;
@weakify(self)
[ZLPhotoManager requestAssetFileUrl:asset complete:^(NSString * _Nonnull filePath) {
@strongify(self)
NSDictionary *opts = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:AVURLAssetPreferPreciseDurationAndTimingKey];
AVURLAsset *urlAsset = [AVURLAsset URLAssetWithURL:[NSURL URLWithString:filePath] options:opts];
NSString *path = [FileToolsObject libraryDir];
dispatch_async(dispatch_get_main_queue(), ^{
@strongify(self);
@autoreleasepool {
[self movFileTransformToMP4WithSourceUrl:urlAsset.URL completion:^(NSURL *Mp4FilePath) {
@strongify(self);
NSString * thumbImagePath1 = [NSString stringWithFormat:@"source/report/video/%@.mp4",[ToolsObject dateChangeRealtimestamp]];
self.VideofileUrl = [path stringByAppendingPathComponent:thumbImagePath1];
[FileToolsObject createFileAtPath:self.VideofileUrl overwrite:YES];
NSData * mp4Data = [NSData dataWithContentsOfURL:urlAsset.URL];
[FileToolsObject writeFileAtPath:self.VideofileUrl content:mp4Data];
[self reloadImagesViewUI];
}];
}
});
}];
}else if (asset.mediaType == PHAssetMediaTypeImage){
self.uploadType = @"img";
[[self mutableArrayValueForKey:@"imagesArray"] removeObject:[UIImage imageNamed:@"myinfo_43"]];
[[self mutableArrayValueForKey:@"imagesArray"] addObjectsFromArray:imageArr];
[self reloadImagesViewUI];
}
}
- (void)movFileTransformToMP4WithSourceUrl:(NSURL *)sourceUrl completion:(void(^)(NSURL *Mp4FilePath))comepleteBlock {
AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:sourceUrl options:nil];
NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:avAsset];
if ([compatiblePresets containsObject:AVAssetExportPresetHighestQuality]) {
AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:avAsset presetName:AVAssetExportPresetMediumQuality];
NSDateFormatter *formater = [[NSDateFormatter alloc] init];
[formater setDateFormat:@"yyyy-MM-dd-HH:mm:ss"];
NSString * resultPath = [NSHomeDirectory() stringByAppendingFormat:@"/Documents/output-%@.mp4", [formater stringFromDate:[NSDate date]]];
exportSession.outputURL = [NSURL fileURLWithPath:resultPath];
exportSession.outputFileType = AVFileTypeMPEG4;
exportSession.shouldOptimizeForNetworkUse = YES;
[exportSession exportAsynchronouslyWithCompletionHandler:^(void) {
switch (exportSession.status) {
case AVAssetExportSessionStatusUnknown:
NSLog(@"AVAssetExportSessionStatusUnknown");
break;
case AVAssetExportSessionStatusWaiting:
NSLog(@"AVAssetExportSessionStatusWaiting");
break;
case AVAssetExportSessionStatusExporting:
NSLog(@"AVAssetExportSessionStatusExporting");
break;
case AVAssetExportSessionStatusCompleted:
comepleteBlock(exportSession.outputURL);
break;
case AVAssetExportSessionStatusFailed:
NSLog(@"AVAssetExportSessionStatusFailed");
break;
default:
break;
}
}];
}
}
/*
#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.
}
*/
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[IQKeyboardManager sharedManager].enable = YES;
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[IQKeyboardManager sharedManager].enable = NO;
}
@end