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];

}];
}

最新文章

  1. Binary Tree Inorder Traversal
  2. GJM: Unity3D AssetBundle 手记 [转载]
  3. linux 文件管理以及其相关指令
  4. BZOJ1588——[HNOI2002]营业额统计
  5. WPF中ComboBox绑定数据库自动读取产生数据
  6. java基础十一[远程部署的RMI](阅读Head First Java记录)
  7. Google首席软件工程师Joshua Bloch谈如何设计一款优秀的API【附PPT】
  8. DbUtils使用例子
  9. 数组(Array)的使用方法
  10. Chrome 插件vimium快捷键大全
  11. Android 它们的定义ContentProvider和ContentObserver充分利用
  12. 第三篇——第二部分——第二文 计划搭建SQL Server镜像
  13. CentOS 手动增加、删除swap区
  14. EntityFramework 6.x多个上下文迁移实现分布式事务
  15. Caused by: java.lang.ClassNotFoundException: org.springframework.context.ApplicationContextAware
  16. Spring Cloud中服务的发现与消费
  17. C++之标准库vector
  18. LIGER UI GRID TREE解决打开子树的时候,母树图标全部变成+
  19. 搭建RISC-V错误记录
  20. CString/string 区别及其转化

热门文章

  1. MySQL之profiling性能分析(在5.6.14版本被丢弃)
  2. Pycharm----设置默认脚本请求头
  3. vue slot及用法,$slots访问具名slot
  4. Django内置email发送邮件
  5. 【leetcode】1240. Tiling a Rectangle with the Fewest Squares
  6. 基本数据类型-MySQL
  7. LOJ #121. 「离线可过」动态图连通性 LCT维护最大生成树
  8. setsockopt函数
  9. (转)Git操作
  10. codeforces392B