iDevice camera shows black instead of preview

后端 未结 4 2174
失恋的感觉
失恋的感觉 2020-12-05 16:06

\"enterI am developing an app that captures images from iDevice\'s camera and upload it to web

4条回答
  •  一个人的身影
    2020-12-05 16:38

    I had faced this issue in my app. Though I never found out the what the issue was, I rewrote my code to define a property of UIIMagePickerController type and initialize it once in the getter. Used this property to initialize the camera view :

    getter:

    -(UIImagePickerController *) imagePicker{
        if(!_imagePicker){
           _imagePicker = [[UIImagePickerController alloc] init];
           _imagePicker.delegate = self;
           if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
               _imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
           }
           else{
               _imagePicker.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
           }  
    
       }
        return _imagePicker;
    }
    
    
    - (IBAction)addNewImage:(id)sender{
      if (self.imagePicker)
      {
          [self presentViewController:self.imagePicker animated:YES completion:^{}];
      }
    }
    

    For some reason this got rid of the issue with preview sometimes showing a black screen

提交回复
热议问题