这是在测试项目的时候,发现上传用户头像有一个问题,然后引发的探索:
代码:
/**
修改头像
*/
- (void)modifyHeadshot {
/*头像*/
NSString *mediaType = AVMediaTypeVideo;
AVAuthorizationStatus authorizationStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];
if (authorizationStatus == AVAuthorizationStatusRestricted || authorizationStatus == AVAuthorizationStatusDenied) {
/*询问是否允许使用照相机*/
UIAlertController * alertC = [UIAlertController alertControllerWithTitle:@"摄像头访问受限" message:@"请去设置中修改权限" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
[self dismissViewControllerAnimated:YES completion:nil];
}];
[alertC addAction:action];
[self presentViewController:alertC animated:YES completion:nil];
}else{
UIAlertController *alertController = [[UIAlertController alloc] init];
UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"从手机相册选择" style:0 handler:^(UIAlertAction * _Nonnull action) {
LOG(@"从手机相册选择"