zoukankan      html  css  js  c++  java
  • iOS-上传头像的使用

    static NSString *const uploadSuccess = @"更改头像成功";

    @interface DMAccountInformationViewController ()<UIImagePickerControllerDelegate, UINavigationControllerDelegate,UIActionSheetDelegate,AVAudioPlayerDelegate>

    @property (nonatomic, strong) UIImageView *pictureImageView;    //头像

    @property (nonatomic, strong) UIImage  *changeImage;

    #pragma mark - ---------------- 事件 ------------------
    #pragma mark - 选择照片
    - (void)choosePhotoAction
    {
        UIActionSheet *actionSheet=[[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"拍照",@"从相册中选取", nil];
        [actionSheet showInView:self.view];
    }
    #pragma mark -actionsheet delegate
    - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
    {
        UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
        if (buttonIndex==0) {
            
            NSString * mediaType = AVMediaTypeVideo;
            AVAuthorizationStatus  authorizationStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];
            if (authorizationStatus == AVAuthorizationStatusRestricted|| authorizationStatus == AVAuthorizationStatusDenied) {
                if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1) {
                    
                    UIAlertController * alertC = [UIAlertController alertControllerWithTitle:@"摄像头访问受限" message:nil preferredStyle:UIAlertControllerStyleAlert];
                    [self presentViewController:alertC animated:YES completion:nil];
                    UIAlertAction * action = [UIAlertAction  actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
                        [self dismissViewControllerAnimated:YES completion:nil];
                    }];
                    [alertC addAction:action];
                }else
                {
                    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"摄像头访问受限" message:nil delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
                    [alertView show];
                    
                }
                
            }else{
                
            }
            
            if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
            {
                imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
                imagePicker.allowsEditing = YES;
                imagePicker.delegate = self;
                [self presentViewController:imagePicker animated:YES completion:nil];
            }
            else
            {
                UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"该设备相机不能使用" delegate:nil cancelButtonTitle:@"关闭" otherButtonTitles:nil];
                [alert show];
            }
        }else if (buttonIndex==1)
        {
            imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            imagePicker.allowsEditing = YES;
            imagePicker.delegate = self;
            [self presentViewController:imagePicker animated:YES completion:nil];
        }
    }

    #pragma mark - ---------------- 请求 ------------------
    #pragma mark - 上传图片请求
    - (void)uploadImgRequestWithPatameters:(NSDictionary *)parameters
    {
        [DMHttpRequest postUploadFile:DMUploadIconUrl parameters:parameters success:^(id responseObj) {
            NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:responseObj options:NSJSONReadingAllowFragments error:nil];
            DMRequestCode code = [DMTools responseCode:dictionary];
            NSLog(@"!!%@!!",dictionary);
            switch (code) {
                case DMRequestSuccess:
                {
                    NSLog(@"!!%@!!",dictionary);
                    [DMTools loadSuccessHUD:self.hud text:uploadSuccess delay:DMHUDDelayTimeInterval];
                    
                    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                        NSDictionary *imageDic = [dictionary objectForKey:@"data"];
                        NSString *imageStr = [imageDic objectForKey:@"url"];
                        
                        dispatch_async(dispatch_get_main_queue(), ^{
                            
                            [DMUserLogInfoModel shareInstance].userData.avatar = imageStr;
                            
                            [DMUserDataManager saveUserData:[DMUserLogInfoModel shareInstance].userData.keyValues];
                  
                            _pictureImageView.image = _changeImage;
                        });
                    });
                    
                    
    dispatch_get_main_queue(), ^{
                
                    break;
                }
                default:
                    [DMTools loadFailedHUD:self.hud text:[DMTools responseMessage:dictionary] delay:DMHUDDelayTimeInterval];

                    break;
            }
        } failure:^(NSError *error) {
            [DMTools loadFailedHUD:self.hud text:DMRequestFailureNote delay:DMHUDDelayTimeInterval];

        }];
    }

  • 相关阅读:
    js数组从小到大排序
    高效率去掉js数组中重复项
    Oracle start with.connect by prior子句实现递归查询
    ofbiz进击 。 ofbiz 退货流程(包含获取可退货项流程分析 以及 取消退货项的过程分析)
    ofbiz进击 个人遇到的奇葩问题汇总。
    ofbiz进击 第六节。 --OFBiz配置之[widget.properties] 配置属性的分析
    ofbiz进击 第五节。 --OFBiz配置之[general.properties] 共有属性的分析(含email)
    ofbiz进击 第四节。 我的form之旅
    &nbsp|&quot|&amp|&lt|&gt等html字符转义
    ofbiz进击 第三节。 各个关键文件的说明与作用
  • 原文地址:https://www.cnblogs.com/linxiu-0925/p/5389926.html
Copyright © 2011-2022 走看看