- (void)initActionSheet
{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"我的相册",@"拍照", nil];
actionSheet.tintColor = [UIColor whiteColor];
[actionSheet showInView:self.scrollerViewUpload];
}
#pragma mark - UIActionSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0)
{
UIImagePickerController *PickerController = [[UIImagePickerController alloc] init];
PickerController.delegate = self;
[self presentViewController:PickerController animated:YES completion:nil];
}
else if (buttonIndex == 1)
{
DNLog(@"拍照");
UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
//判断是否有相机
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]){
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
//设置拍照后的图片可被编辑
picker.allowsEditing = YES;
//资源类型为照相机
picker.sourceType = sourceType;
[self presentViewController:picker animated:YES completion:nil];
}else {
[SVProgressHUD showWithStatus:@"没有照相功能" maskType:SVProgressHUDMaskTypeBlack];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[SVProgressHUD dismiss];
});
DNLog(@"没有照相功能");
}
}
}
#pragma mark - UIImagePickerControllerDelegate
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
UIImage *imageNew =info[UIImagePickerControllerOriginalImage];
//设置image的尺寸
CGSize imagesize = imageNew.size;
imagesize.width = imageNew.size.width * 0.45;
imagesize.height = imageNew.size.height *0.45;
//对图片大小进行压缩--
// imageNew = [self imageWithImage:imageNew scaledToSize:imagesize];
imageNew = [AppGlobleReciveInfo imageWithImage:imageNew scaledToSize:imagesize];
NSData *imageData = UIImageJPEGRepresentation(imageNew,0.00001);
_selectImage = [UIImage imageWithData:imageData];
self.TravelCardView.image = _selectImage;
[AppGlobleReciveInfo saveWith:_TravelCardView.image nameStr:TravelCardName];
self.TravelCenterBtn.hidden =YES;
self.TravelLable.hidden = YES;
AppGlobleRecive.isTravelCardUpLoadSuccess = false;
[AppGlobleRecive setBool:AppGlobleRecive.isTravelCardUpLoadSuccess forKey:BoolTravelCardUpLoad];
[[NSNotificationCenter defaultCenter] postNotificationName:@"IsSuccessUpLoadIdCard" object:nil];
[picker dismissViewControllerAnimated:YES completion:nil];
}
/**************** 图片上传 ****************/
+(void)uploadImageWithRequest:(NSString *)requestStr fromImage:(UIImage *)image completionHandler:(completionHandler )completionHandler
{
AFHTTPSessionManager *sessionManager = [AFHTTPSessionManager manager];
NSURL * url = [NSURL URLWithString:requestStr];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSData *imageData = UIImageJPEGRepresentation(image, 1.0);
[sessionManager uploadTaskWithRequest:request fromData:imageData progress:nil completionHandler:^(NSURLResponse * _Nonnull response, id _Nullable responseObject, NSError * _Nullable error)
{
completionHandler(response,responseObject,error);
}];
}