Commit f654d33e345f9fa6d4c4798dfb1abac51cfc172e
1 parent
f1f6abd5
no message
Showing
1 changed file
with
87 additions
and
23 deletions
CNLiveMineModule/Classes/UserInfo/CNLiveInfoUpdateController.m
| @@ -261,39 +261,51 @@ static const CGFloat timeValue = 1.5; | @@ -261,39 +261,51 @@ static const CGFloat timeValue = 1.5; | ||
| 261 | QMUIAlertAction *action1 = [QMUIAlertAction actionWithTitle:@"拍照" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) { | 261 | QMUIAlertAction *action1 = [QMUIAlertAction actionWithTitle:@"拍照" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) { |
| 262 | __strong typeof(weakSelf) strongSelf = weakSelf; | 262 | __strong typeof(weakSelf) strongSelf = weakSelf; |
| 263 | if(!strongSelf) return ; | 263 | if(!strongSelf) return ; |
| 264 | - XFCameraController *cameraController = [[XFCameraController alloc] init]; | ||
| 265 | - cameraController.isCanShootVideo = NO; | ||
| 266 | - cameraController.modalPresentationStyle = UIModalPresentationFullScreen; | ||
| 267 | - __weak XFCameraController *weakCameraController = cameraController; | ||
| 268 | - __weak typeof(self) weakSelf = self; | ||
| 269 | - cameraController.takePhotosCompletionBlock = ^(UIImage *image, NSError *error) { | 264 | + strongSelf.navigationBar.right.userInteractionEnabled = YES; |
| 265 | + __strong typeof(strongSelf) weakSelf = strongSelf; | ||
| 266 | + [strongSelf getAVAuthorizationStatus:^{ | ||
| 270 | __strong typeof(weakSelf) strongSelf = weakSelf; | 267 | __strong typeof(weakSelf) strongSelf = weakSelf; |
| 271 | if(!strongSelf) return ; | 268 | if(!strongSelf) return ; |
| 272 | - strongSelf->_image = image; | ||
| 273 | - [strongSelf requestUpdateUserHeader:image]; | ||
| 274 | - dispatch_async(dispatch_get_main_queue(), ^{ | ||
| 275 | - [weakCameraController dismissViewControllerAnimated:YES completion:nil]; | ||
| 276 | - }); | ||
| 277 | - }; | ||
| 278 | - [self presentViewController:cameraController animated:YES completion:nil]; | ||
| 279 | - self.navigationBar.right.userInteractionEnabled = YES; | 269 | + XFCameraController *cameraController = [[XFCameraController alloc] init]; |
| 270 | + cameraController.isCanShootVideo = NO; | ||
| 271 | + cameraController.modalPresentationStyle = UIModalPresentationFullScreen; | ||
| 272 | + __weak XFCameraController *weakCameraController = cameraController; | ||
| 273 | + __weak typeof(strongSelf) weakSelf = strongSelf; | ||
| 274 | + cameraController.takePhotosCompletionBlock = ^(UIImage *image, NSError *error) { | ||
| 275 | + __strong typeof(weakSelf) strongSelf = weakSelf; | ||
| 276 | + if(!strongSelf) return ; | ||
| 277 | + strongSelf->_image = image; | ||
| 278 | + [strongSelf requestUpdateUserHeader:image]; | ||
| 279 | + | ||
| 280 | + dispatch_async(dispatch_get_main_queue(), ^{ | ||
| 281 | + [weakCameraController dismissViewControllerAnimated:YES completion:nil]; | ||
| 282 | + }); | ||
| 283 | + }; | ||
| 284 | + [self presentViewController:cameraController animated:YES completion:nil]; | ||
| 285 | + }]; | ||
| 286 | + | ||
| 280 | }]; | 287 | }]; |
| 281 | QMUIAlertAction *action2 = [QMUIAlertAction actionWithTitle:@"从手机相册中选择" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) { | 288 | QMUIAlertAction *action2 = [QMUIAlertAction actionWithTitle:@"从手机相册中选择" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) { |
| 282 | __strong typeof(weakSelf) strongSelf = weakSelf; | 289 | __strong typeof(weakSelf) strongSelf = weakSelf; |
| 283 | if(!strongSelf) return ; | 290 | if(!strongSelf) return ; |
| 284 | strongSelf.navigationBar.right.userInteractionEnabled = YES; | 291 | strongSelf.navigationBar.right.userInteractionEnabled = YES; |
| 285 | - TZImagePickerController *picker = [[TZImagePickerController alloc] initWithMaxImagesCount:1 delegate:strongSelf]; | ||
| 286 | - picker.modalPresentationStyle = UIModalPresentationFullScreen; | ||
| 287 | - picker.allowPickingVideo = NO; | ||
| 288 | - picker.allowPreview = NO; | ||
| 289 | - __weak typeof(self) weakSelf = self; | ||
| 290 | - [picker setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) { | 292 | + __strong typeof(strongSelf) weakSelf = strongSelf; |
| 293 | + [strongSelf getPHAuthorizationStatus:^{ | ||
| 291 | __strong typeof(weakSelf) strongSelf = weakSelf; | 294 | __strong typeof(weakSelf) strongSelf = weakSelf; |
| 292 | if(!strongSelf) return ; | 295 | if(!strongSelf) return ; |
| 293 | - strongSelf->_image = [photos firstObject]; | ||
| 294 | - [strongSelf requestUpdateUserHeader:[photos firstObject]]; | 296 | + TZImagePickerController *picker = [[TZImagePickerController alloc] initWithMaxImagesCount:1 delegate:strongSelf]; |
| 297 | + picker.modalPresentationStyle = UIModalPresentationFullScreen; | ||
| 298 | + picker.allowPickingVideo = NO; | ||
| 299 | + picker.allowPreview = NO; | ||
| 300 | + __weak typeof(strongSelf) weakSelf = strongSelf; | ||
| 301 | + [picker setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) { | ||
| 302 | + __strong typeof(weakSelf) strongSelf = weakSelf; | ||
| 303 | + if(!strongSelf) return ; | ||
| 304 | + strongSelf->_image = [photos firstObject]; | ||
| 305 | + [strongSelf requestUpdateUserHeader:[photos firstObject]]; | ||
| 306 | + }]; | ||
| 307 | + [strongSelf presentViewController:picker animated:YES completion:nil]; | ||
| 295 | }]; | 308 | }]; |
| 296 | - [self presentViewController:picker animated:YES completion:nil]; | ||
| 297 | 309 | ||
| 298 | }]; | 310 | }]; |
| 299 | QMUIAlertAction *action3 = [QMUIAlertAction actionWithTitle:@"保存图片" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) { | 311 | QMUIAlertAction *action3 = [QMUIAlertAction actionWithTitle:@"保存图片" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) { |
| @@ -364,6 +376,58 @@ static const CGFloat timeValue = 1.5; | @@ -364,6 +376,58 @@ static const CGFloat timeValue = 1.5; | ||
| 364 | }]; | 376 | }]; |
| 365 | 377 | ||
| 366 | } | 378 | } |
| 379 | + | ||
| 380 | +- (void)getAVAuthorizationStatus:(void (^)(void))block{ | ||
| 381 | + AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; | ||
| 382 | + if (device) { | ||
| 383 | + AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; | ||
| 384 | + switch (status) { | ||
| 385 | + case AVAuthorizationStatusNotDetermined: { | ||
| 386 | + [AVCaptureDevice requestAccessForMediaType:AVMediaTypeVideo completionHandler:^(BOOL granted) { | ||
| 387 | + if (granted) { | ||
| 388 | + dispatch_sync(dispatch_get_main_queue(), ^{ | ||
| 389 | + block(); | ||
| 390 | + }); | ||
| 391 | + NSLog(@"用户第一次同意了访问相机权限 - - %@", [NSThread currentThread]); | ||
| 392 | + } else { | ||
| 393 | + NSLog(@"用户第一次拒绝了访问相机权限 - - %@", [NSThread currentThread]); | ||
| 394 | + } | ||
| 395 | + }]; | ||
| 396 | + break; | ||
| 397 | + } | ||
| 398 | + case AVAuthorizationStatusAuthorized: { | ||
| 399 | + block(); | ||
| 400 | + break; | ||
| 401 | + } | ||
| 402 | + case AVAuthorizationStatusDenied: { | ||
| 403 | + NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary]; | ||
| 404 | + NSString *app_Name = [infoDict objectForKey:@"CFBundleDisplayName"]; | ||
| 405 | + if (app_Name == nil) { | ||
| 406 | + app_Name = [infoDict objectForKey:@"CFBundleName"]; | ||
| 407 | + } | ||
| 408 | + NSString *messageString = [NSString stringWithFormat:@"请在iPhone的\"设置 - 隐私 - 相机\"选项中,允许%@访问你的相机", app_Name]; | ||
| 409 | + UIAlertController *alertC = [UIAlertController alertControllerWithTitle:nil message:messageString preferredStyle:(UIAlertControllerStyleAlert)]; | ||
| 410 | + UIAlertAction *alertA = [UIAlertAction actionWithTitle:@"好" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) { | ||
| 411 | + | ||
| 412 | + }]; | ||
| 413 | + | ||
| 414 | + [alertC addAction:alertA]; | ||
| 415 | + [self presentViewController:alertC animated:YES completion:nil]; | ||
| 416 | + break; | ||
| 417 | + } | ||
| 418 | + case AVAuthorizationStatusRestricted: { | ||
| 419 | + NSLog(@"因为系统原因, 无法访问相册"); | ||
| 420 | + break; | ||
| 421 | + } | ||
| 422 | + | ||
| 423 | + default: | ||
| 424 | + break; | ||
| 425 | + } | ||
| 426 | + return; | ||
| 427 | + } | ||
| 428 | + [QMUITips showError:@"未检测到您的摄像头" inView:self.view hideAfterDelay:timeValue]; | ||
| 429 | +} | ||
| 430 | + | ||
| 367 | - (void)getPHAuthorizationStatus:(void (^)(void))block{ | 431 | - (void)getPHAuthorizationStatus:(void (^)(void))block{ |
| 368 | // 1.获取当前App的相册授权状态 | 432 | // 1.获取当前App的相册授权状态 |
| 369 | PHAuthorizationStatus authorizationStatus = [PHPhotoLibrary authorizationStatus]; | 433 | PHAuthorizationStatus authorizationStatus = [PHPhotoLibrary authorizationStatus]; |