【问题标题】:iOS camera permissions :Camera appears black on iphone and ipad(UIImagePickerController issue iOS 9 )iOS 相机权限:相机在 iphone 和 ipad 上显示为黑色(UIImagePickerController 问题 iOS 9)
【发布时间】:2016-03-17 05:53:06
【问题描述】:

在我的应用程序中,我使用以下代码访问相机以更改用户的个人资料图片。但我无法访问相机。

 if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])
    {
        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.delegate = self;
        picker.allowsEditing = YES;
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
 if(isIOS8SystemVersion)
        {
            [[NSOperationQueue mainQueue] addOperationWithBlock:^{
                [self presentViewController:picker animated:YES completion:NULL];
            }];
        }
        else
        {
            [self presentViewController:picker animated:YES completion:NULL];
        }

此代码在 iOS 7.x 的 iPhone 4(16gb) 上运行良好。但在 iOS 9 中,呈现的 viewController 显示为黑屏,我无法拍照。同样是photoLibrary 的情况。相同的代码适用于我在同一设备上的其他应用程序。

我在 Stack Overflow 中遇到了很多问题并尝试了很多解决方案。但它们对我不起作用。比如为 UIImagePIcker 控制器等制作单例。

settings->privacy->camera->我看不到我的应用列在这个部分。

为了让 iOS 应用程序可以访问相机和照片,需要做哪些事情?我错过了什么吗?

【问题讨论】:

    标签: ios iphone ipad uiimagepickercontroller


    【解决方案1】:

    只需延迟您的功能以打开相机,它就会正常工作:D 使用以下代码:

    [self performSelector:@selector(showCamera) withObject:nil afterDelay:1.0];
    
    
    -(void)showCamera
    {
    if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])
    {
        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.delegate = self;
        picker.allowsEditing = YES;
        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
        if(isIOS8SystemVersion)
        {
            [[NSOperationQueue mainQueue] addOperationWithBlock:^{
                [self presentViewController:picker animated:YES completion:NULL];
            }];
        }
        else
        {
            [self presentViewController:picker animated:YES completion:NULL];
        }
    }
    

    【讨论】:

      【解决方案2】:

      首先调用该方法并判断摄像头的权限

      -(void)PermissionForCamera
      {
          NSString *mediaType = AVMediaTypeVideo;
          AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];
      
          if(authStatus == AVAuthorizationStatusAuthorized)
          {
              NSLog(@"AVAuthorizationStatusAuthorized");
              // run your code for camera
              ImagePicker = [[UIImagePickerController alloc] init];
              [ImagePicker setDelegate:self];
              ImagePicker = UIImagePickerControllerSourceTypeCamera;
      
              [[NSOperationQueue mainQueue] addOperationWithBlock:^{
                  [self ImagePicker animated:YES completion:nil];
              }];
          }
          else if(authStatus == AVAuthorizationStatusNotDetermined)
          {
              NSLog(@"AVAuthorizationStatusNotDetermined");
              // run your code for camera
              ImagePicker = [[UIImagePickerController alloc] init];
              [ImagePicker setDelegate:self];
              ImagePicker = UIImagePickerControllerSourceTypeCamera;
      
              [[NSOperationQueue mainQueue] addOperationWithBlock:^{
                  [self ImagePicker animated:YES completion:nil];
              }];
          }
          else
          {
              // turn on the camera permission from settings
          }
      
      
      }
      

      【讨论】:

      • 这只是一个通常的权限检查吧?我的问题是没有授予使用相机的访问权限,并且在设置->隐私->相机->我看不到我的应用程序列出在本节中。
      • 如果你或其他人还在看,设置不在隐私之下,它在设置->[你的应用]->相机下。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-06
      • 1970-01-01
      • 2011-04-03
      • 2023-03-20
      相关资源
      最近更新 更多