Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/41.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone iDevice摄像头显示黑色而不是预览_Iphone_Ios_Ipad_Camera - Fatal编程技术网

Iphone iDevice摄像头显示黑色而不是预览

Iphone iDevice摄像头显示黑色而不是预览,iphone,ios,ipad,camera,Iphone,Ios,Ipad,Camera,我正在开发一个应用程序,从iDevice的相机中捕获图像并上传到web服务 没问题,除了设备的摄像头外,一切正常。设备的摄像头快把我逼疯了。我使用下面的代码允许用户捕获图像。相机有时显示预览,有时不显示预览。而不是预览只是在屏幕上显示完全黑暗。如果我从后到前切换,摄像头开始工作正常。我甚至尝试从设备中删除所有后台应用程序,并尽可能多地清除内存;还是没有运气,我被困住了( 我在应用程序中遇到了此问题。虽然我从未发现问题所在,但我重写了代码以定义UIIMagePickerController的属性,

我正在开发一个应用程序,从iDevice的相机中捕获图像并上传到web服务

没问题,除了设备的摄像头外,一切正常。设备的摄像头快把我逼疯了。我使用下面的代码允许用户捕获图像。相机有时显示预览,有时不显示预览。而不是预览只是在屏幕上显示完全黑暗。如果我从后到前切换,摄像头开始工作正常。我甚至尝试从设备中删除所有后台应用程序,并尽可能多地清除内存;还是没有运气,我被困住了(


我在应用程序中遇到了此问题。虽然我从未发现问题所在,但我重写了代码以定义
UIIMagePickerController
的属性,并在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:^{}];
  }
}

出于某种原因,这解决了ios7中预览有时会显示黑屏的问题,您应该设置mainWindow.rootViewController=类的种类是UIViewController。这对我来说很有用。
如果rootViewController是其他的,例如:UITabbarController,UINavigationController…,相机的黑屏就会出现。

我在iOS7中面临同样的问题大约一个月了,在对整个应用程序进行了长时间的令人头痛的代码检查之后,我能够识别出这个问题。 我在列举一个
iOutletCollection(UILabel)NSArray*静态标签集合; 数组同时更新标签文本,这些文本在多个线程上同时执行

[self.labelsArr enumerateObjectsWithOptions:NSEnumerationConcurrent usingBlock:^(id obj, NSUInteger idx, BOOL *stop) {

    UILabel * label = (UILabel*)obj;

    label.text=[NSString stringWithFormat:@"%d",idx+2];

}];
这就产生了在非主线程上更新UIKit元素的问题。 通过在Xcode中启用环境变量CA_DEBUG_TRANSACTIONS=1,我发现了这个问题,它在设备控制台中生成了警告

Nov 20 18:40:26 iPad2 CameraTest[1757] <Warning>: CoreAnimation: warning, deleted thread with uncommitted CATransaction; created by:
 0   QuartzCore                          0x32a553b3 <redacted> + 266
 1   QuartzCore                          0x32a55269 <redacted> + 224
 2   QuartzCore                          0x32a56871 <redacted> + 24
 3   QuartzCore                          0x32a56eed <redacted> + 40
 4   QuartzCore                          0x32a619ed <redacted> + 412
 5   QuartzCore                          0x32a6184b <redacted> + 46
 6   QuartzCore                          0x32a61819 <redacted> + 44
 7   UIKit                               0x32ddfe53 <redacted> + 86
 8   CameraTest                          0x000923b5 __35-[ViewController blockEnumeration:]_block_invoke + 184
 9   CoreFoundation                      0x305aa821 <redacted> + 92
 10  libdispatch.dylib                   0x3b3308eb <redacted> + 134
 11  libdispatch.dylib                   0x3b32fd71 <redacted> + 220
 12  libdispatch.dylib                   0x3b32ff59 <redacted> + 56
 13  libsystem_pthread.dylib             0x3b46adbf _pthread_wqthread + 298
 14  libsystem_pthread.dylib             0x3b46ac84 start_wqthread + 8
Nov 20 18:40:26 iPad2 CameraTest[1757]:CoreAnimation:警告,已删除未提交CATTransaction的线程;创建人:
0夸脱芯0x32a553b3+266
1夸脱芯0x32a55269+224
2夸脱芯0x32a56871+24
3夸脱芯0x32a56eed+40
4夸脱芯0x32a619ed+412
5夸脱芯0x32a6184b+46
6夸脱芯0x32a61819+44
7 UIKit 0x32ddfe53+86
8 CameraTest 0x000923b5 _u35-[ViewController blockEnumeration:]block_invoke+184
9芯基础0x305aa821+92
10 libdispatch.dylib 0x3b3308eb+134
11 libdispatch.dylib 0x3b32fd71+220
12 libdispatch.dylib 0x3b32ff59+56
13 libsystem_pthread.dylib 0x3b46adbf_pthread_wqthread+298
14 libsystem_pthread.dylib 0x3b46ac84 start_wqthread+8
通过强制它们在主线程上运行来修复这些“未限制的CATTransaction”,修复了黑摄像头问题。 我可以通过从枚举中删除选项:NSEnumerationConcurrent来修复它

可以下载可以不断重现问题的示例应用程序


希望示例应用程序能够提供一些见解和解决问题的方法。

我有一位客户有此问题。他们一定选择了不允许访问摄像头。我们必须在“设置”中更改应用程序的摄像头隐私设置。当我们重新打开该设置时,不再有黑色摄像头屏幕。

您的屏幕上没有任何突出的内容代码不正确(除非在您确认
isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera
返回
YES
后,我会初始化您的
UIImagePickerController
)。这是否只发生在一台设备上?如果是,可能是您的相机出现故障。您在其他设备上测试过吗?是的,我在iPhone 4、iPad2和iPad4上测试过。它也会出现同样的问题。请提供任何线索。我已在相机上附加了我的视图的屏幕截图。您是否尝试使用唯一的按钮创建新的单视图项目这就叫你的
addNewImage:
?我试过了,效果和预期一样。可能是重复的感谢凯达的回复。我试过了你给出的代码片段,但这个技巧似乎不起作用。相机显示预览,但需要2-4秒的时间。有什么线索吗?你有一些块在GCD上运行吗启动imagepickercontroller时出现的问题?我也看到了导致此问题的原因。抱歉,没有更多明确的线索。当CGD队列中执行的块太多且优先级为DISPATCH\u queue\u priority\u DEFAULT时,我发现了此问题。NSOperationQueue应该可以。您仍然可以检查是否有任何操作正在执行启动控制器时执行,如果停止操作会有帮助,但我认为这没有关系。感谢Kedar的帮助。让我试试你的建议。嗨,你试过apple developer的这个示例吗?。没有显示黑色预览屏幕。首先,我在主窗口中设置了uitabbarcontroller为rootviewController。黑色预览有时会显示。之后,我将uiviewcontroller设置为rootviewcontroller。不会出现黑色预览。感谢您共享链接,我将尝试此链接。这些有趣的客户:)谢谢,并最终找出了它在我客户的手机上不起作用的原因。是的,这是一种爱恨关系。。。我们随后输入代码来检测它何时被停用,并在登录屏幕上显示警告。在“设置”->“隐私”->“相机”->“我看不到本节中列出的我的应用程序。我做错了什么?我的相机显示为黑色。转到“设置”->“应用程序名”(示例:Youtube)->“相机”->“你可以看到开关按钮”->“你已经启用了它”。
Nov 20 18:40:26 iPad2 CameraTest[1757] <Warning>: CoreAnimation: warning, deleted thread with uncommitted CATransaction; created by:
 0   QuartzCore                          0x32a553b3 <redacted> + 266
 1   QuartzCore                          0x32a55269 <redacted> + 224
 2   QuartzCore                          0x32a56871 <redacted> + 24
 3   QuartzCore                          0x32a56eed <redacted> + 40
 4   QuartzCore                          0x32a619ed <redacted> + 412
 5   QuartzCore                          0x32a6184b <redacted> + 46
 6   QuartzCore                          0x32a61819 <redacted> + 44
 7   UIKit                               0x32ddfe53 <redacted> + 86
 8   CameraTest                          0x000923b5 __35-[ViewController blockEnumeration:]_block_invoke + 184
 9   CoreFoundation                      0x305aa821 <redacted> + 92
 10  libdispatch.dylib                   0x3b3308eb <redacted> + 134
 11  libdispatch.dylib                   0x3b32fd71 <redacted> + 220
 12  libdispatch.dylib                   0x3b32ff59 <redacted> + 56
 13  libsystem_pthread.dylib             0x3b46adbf _pthread_wqthread + 298
 14  libsystem_pthread.dylib             0x3b46ac84 start_wqthread + 8