- (void)initActionSheet { UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButto ...
- (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);
}];
}