iOS 拍照上传 并压缩(压缩图片并上传)

iOS 拍照上传 并压缩(压缩图片并上传),第1张

概述iOS 拍照上传 并压缩(压缩图片并上传) @H_301_0@下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。

@H_301_0@内存溢出小编现在分享给大家,也给大家做个参考。

iOS中常常需要打开相机 选择图片 或者拍着上传  一直遇到问题这次解决后就分享一下  
#pragma mark - 打开相机-(voID)imagePickerController:(UIImagePickerController *)picker dIDFinishPickingMediawithInfo:(NSDictionary<Nsstring *,ID> *)info{    UIImage *image = info[UIImagePickerControllerOriginalimage];    self.currentTapCell.photoManageimgVIEw.image = image;    NSIndexPath * indexPath = [self.basetable indexPathForCell:self.currentTapCell];    Nsstring * key = [Nsstring stringWithFormat:@"ineed%u%u",indexPath.row,indexPath.section];       [[NetEngineHelper shareNetEngine] postUploaDWithUrl:k_uploadPhoto_url image:image filename:[Nsstring stringWithFormat:@"%@.png",key] fileType:@"PNG/JPEG/JPG" success:^(ID response) {        if ([response[@"STATUS"] intValue] != 0) {            Nsstring * str = @"";            if (response[@"ERRORDESC"]) {                str = response[@"ERRORDESC"];            }else{                str = @"系统异常";            }            [AlertHelper shareAlertHelper].onVC = self;            [AlertHelper shareAlertHelper].alertTitle = str;            [AlertHelper shareAlertHelper].alertMessage = nil;            [[AlertHelper shareAlertHelper] alertVcWithSureAction:^(ID response) {                            }];        }else{            [AlertHelper shareAlertHelper].onVC = self;            [AlertHelper shareAlertHelper].alertTitle = @"上传成功";            [AlertHelper shareAlertHelper].alertMessage = nil;            [[AlertHelper shareAlertHelper] alertVcWithSureAction:^(ID response) {                            }];                        if ([self.currentTapCell.photoDescribeLable.text isEqualToString:@"上传诊断证明"]) {                [self.successuploadDic setValue:response[@"fileID"] forKey:@"PROVEID"];            }            if ([self.currentTapCell.photoDescribeLable.text isEqualToString:@"上传病历首页"]){                [self.successuploadDic setValue:response[@"fileID"] forKey:@"CASEHOMEID"];            }                                                NSLog(@"上传结果   %@",response);        }    } fail:^(NSError *error) {        [AlertHelper shareAlertHelper].onVC = self;        [AlertHelper shareAlertHelper].alertTitle = error.userInfo[@"NSLocalizedDescription"];        [AlertHelper shareAlertHelper].alertMessage = nil;        [[AlertHelper shareAlertHelper] alertVcWithSureAction:^(ID response) {                    }];    }];            [self dismissVIEwControllerAnimated:YES completion:^{            }];}                   #pragma mark - 打开相机-(voID)imagePickerController:(UIImagePickerController *)picker dIDFinishPickingMediawithInfo:(NSDictionary<Nsstring *,response);        }    } fail:^(NSError *error) {        [AlertHelper shareAlertHelper].onVC = self;        [AlertHelper shareAlertHelper].alertTitle = error.userInfo[@"NSLocalizedDescription"];        [AlertHelper shareAlertHelper].alertMessage = nil;        [[AlertHelper shareAlertHelper] alertVcWithSureAction:^(ID response) {                    }];    }];            [self dismissVIEwControllerAnimated:YES completion:^{            }];}                   /**上传文件*/-(voID)postUploaDWithUrl:(Nsstring *)urlStr image:(UIImage *)image filename:(Nsstring *)filename fileType:(Nsstring *)fileTye success:(Success)success fail:(Faile)fail{        Nsstring * resultStr = [urlStr stringByAddingPercentEnCodingWithAllowedCharacters:[NSCharacterSet URLqueryAllowedCharacterSet]];    self.success = success;    self.failer = fail;    AFhttpRequestoperationManager *manager = [AFhttpRequestoperationManager manager];    manager.responseSerializer = [AFhttpResponseSerializer serializer];    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/HTML",@"application/Json",@"text/plain",nil];    [manager.requestSerializer setValue:@"application/Json" forhttpheaderFIEld:@"Content-Type"];    manager.responseSerializer=[AFJsONResponseSerializer serializer];    manager.requestSerializer = [AFhttpRequestSerializer serializer];    [manager.securityPolicy setAllowInvalIDCertificates:YES];        UIApplication *application = [UIApplication sharedApplication];    application.networkActivityIndicatorVisible = YES;    [manager POST:resultStr parameters:nil constructingBodyWithBlock:^(ID<AFMultipartFormData> formData) {                NSData * imgData = UIImageJPEGRepresentation(image,0.02);        [formData appendPartWithfileData:imgData name:@"filename" filename:filename mimeType:fileTye];                    } success:^(AFhttpRequestoperation *operation,ID responSEObject) {       success(responSEObject);        application.networkActivityIndicatorVisible = NO;    } failure:^(AFhttpRequestoperation *operation,NSError *error) {        fail(error);        application.networkActivityIndicatorVisible = NO;    }];}
@H_301_0@以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

@H_301_0@ 如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

总结

以上是内存溢出为你收集整理的iOS 拍照上传 并压缩(压缩图片并上传)全部内容,希望文章能够帮你解决iOS 拍照上传 并压缩(压缩图片并上传)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1105803.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存