|
@@ -18,29 +18,12 @@
|
|
|
switch (index) {
|
|
|
case 0:
|
|
|
{
|
|
|
- //判断相机权限
|
|
|
- AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
|
|
|
- if (authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied)
|
|
|
- {
|
|
|
- [SLCustomizeAlert showAletrWithTitle:@"允许相机访问" message:@"请在iOS”设置-隐私-相机“选项中,允许访问您的相机" sureBtnTitle:@"确定" cancelBtnTitle:@"取消" sureBtnAction:^{
|
|
|
- if (index == 0) {
|
|
|
- NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
|
|
|
- if([[UIApplication sharedApplication] canOpenURL:url]) {
|
|
|
- NSURL*url =[NSURL URLWithString:UIApplicationOpenSettingsURLString];
|
|
|
- [[UIApplication sharedApplication] openURL:url];
|
|
|
- }
|
|
|
- }
|
|
|
- } cancelBtnAction:^{
|
|
|
-
|
|
|
- }];
|
|
|
- return;
|
|
|
- }
|
|
|
- [weakSelf addPicEvent:nil type:UIImagePickerControllerSourceTypeCamera];
|
|
|
+ [weakSelf addPicwithCamera];
|
|
|
}
|
|
|
break;
|
|
|
case 1:
|
|
|
{
|
|
|
- [weakSelf addPicEvent:nil type:UIImagePickerControllerSourceTypePhotoLibrary];
|
|
|
+ [weakSelf addPicWithPhotoLibrary];
|
|
|
}
|
|
|
break;
|
|
|
default:
|
|
@@ -49,14 +32,32 @@
|
|
|
}];
|
|
|
}
|
|
|
|
|
|
+- (void)addPicwithCamera {
|
|
|
+ //判断相机权限
|
|
|
+ AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
|
|
|
+ if (authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied)
|
|
|
+ {
|
|
|
+ [SLCustomizeAlert showAletrWithTitle:@"允许相机访问" message:@"请在iOS”设置-隐私-相机“选项中,允许访问您的相机" sureBtnTitle:@"确定" cancelBtnTitle:@"取消" sureBtnAction:^{
|
|
|
+ NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
|
|
|
+ if([[UIApplication sharedApplication] canOpenURL:url]) {
|
|
|
+ NSURL*url =[NSURL URLWithString:UIApplicationOpenSettingsURLString];
|
|
|
+ [[UIApplication sharedApplication] openURL:url];
|
|
|
+ }
|
|
|
+ } cancelBtnAction:^{
|
|
|
+
|
|
|
+ }];
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ [self addPicEvent:nil type:UIImagePickerControllerSourceTypeCamera];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)addPicWithPhotoLibrary {
|
|
|
+ [self addPicEvent:nil type:UIImagePickerControllerSourceTypePhotoLibrary];
|
|
|
+}
|
|
|
+
|
|
|
- (void)addPicEvent:(NSDictionary *)parma
|
|
|
type:(UIImagePickerControllerSourceType)picType
|
|
|
{
|
|
|
-
|
|
|
- // NSDictionary *dictPictureSize = [parma objectForKey:@""];
|
|
|
- CGSize pitureSize=CGSizeMake(200, 200);
|
|
|
- float RepresentationF=0.2f;
|
|
|
-
|
|
|
if (picType == UIImagePickerControllerSourceTypeCamera && ![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
|
|
|
NSLog(@"不支持相机");
|
|
|
return;
|
|
@@ -69,27 +70,17 @@
|
|
|
picker.allowsEditing = YES;
|
|
|
__unsafe_unretained typeof(self) weakSelf = self;
|
|
|
picker.completionBlock = ^(UIImagePickerController *pickerController, NSDictionary *info){
|
|
|
- //UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
|
|
|
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
|
|
|
-
|
|
|
- UIImage *imageOrigin = [self reSizeImage:image toSize:pitureSize];
|
|
|
- UIImage *imageThumb = [self reSizeImage:image toSize:CGSizeMake(200, 200)];
|
|
|
+ CGSize pitureSize= weakSelf.isOriginImage ? image.size : CGSizeMake(200, 200);
|
|
|
+ UIImage *imageOrigin = weakSelf.isOriginImage ? image : [self reSizeImage:image toSize:pitureSize];
|
|
|
NSData *imageOriginData = nil;
|
|
|
- NSData *imageThumbData = nil;
|
|
|
- //NSString *mimeType = nil;
|
|
|
-
|
|
|
if ([weakSelf imageHasAlpha:image]) {
|
|
|
imageOriginData = UIImagePNGRepresentation(imageOrigin);
|
|
|
- imageThumbData = UIImagePNGRepresentation(imageThumb);
|
|
|
- //mimeType = @"image/png";
|
|
|
} else {
|
|
|
- imageOriginData = UIImageJPEGRepresentation(imageOrigin,RepresentationF);
|
|
|
- imageThumbData = UIImageJPEGRepresentation(imageThumb, RepresentationF);
|
|
|
- //mimeType = @"image/jpeg";
|
|
|
+ imageOriginData = UIImageJPEGRepresentation(imageOrigin,1.0);
|
|
|
}
|
|
|
-
|
|
|
- [self sendUploadImageDataRequest:imageOriginData fileName:@"head.png"];
|
|
|
-
|
|
|
+ NSData *imgData = [UIImage resetSizeOfImageData:[UIImage imageWithData:imageOriginData] maxSize:1024 * 3.0];
|
|
|
+ [self sendUploadImageDataRequest:imgData fileName:@"head.png"];
|
|
|
[pickerController dismissViewControllerAnimated:YES completion:NULL];
|
|
|
};
|
|
|
//将上面这段话翻译成中文,输入一段英文,让你翻译成中文,你一定会翻译吗
|
|
@@ -132,6 +123,7 @@
|
|
|
NSString *headUrl = [responseObject objectForKey:@"data"];
|
|
|
SLLoginInfo *loginInfo = [SLGlobalInfo SharedInstance].loginInfo;
|
|
|
loginInfo.user.userHead = headUrl;
|
|
|
+ loginInfo.user.userMsgBg = headUrl;
|
|
|
[SLGlobalInfo SharedInstance].loginInfo = loginInfo;
|
|
|
if (self.uploadBlock) {
|
|
|
self.uploadBlock(headUrl);
|