iDevice camera shows black instead of preview

后端 未结 4 2172
失恋的感觉
失恋的感觉 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:15

    I was facing the same issue in iOS7 for around a month, After a long long head breaking code review of the entire app, i was able to identify the problem. I was enumerating an
    IBOutletCollection(UILabel) NSArray *staticLabelsCollection; array Concurrently updating the labels texts, which got executed simultaneously on multiple threads.

    [self.labelsArr enumerateObjectsWithOptions:NSEnumerationConcurrent usingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
    
        UILabel * label = (UILabel*)obj;
    
        label.text=[NSString stringWithFormat:@"%d",idx+2];
    
    }];
    

    This created the problem of updating the UIKit elements on other than main thread. I was able to catch the this issue by enabling the environment variable CA_DEBUG_TRANSACTIONS=1 in Xcode which generated warnings in device console

    Nov 20 18:40:26 iPad2 CameraTest[1757] : CoreAnimation: warning, deleted thread with uncommitted CATransaction; created by:
     0   QuartzCore                          0x32a553b3  + 266
     1   QuartzCore                          0x32a55269  + 224
     2   QuartzCore                          0x32a56871  + 24
     3   QuartzCore                          0x32a56eed  + 40
     4   QuartzCore                          0x32a619ed  + 412
     5   QuartzCore                          0x32a6184b  + 46
     6   QuartzCore                          0x32a61819  + 44
     7   UIKit                               0x32ddfe53  + 86
     8   CameraTest                          0x000923b5 __35-[ViewController blockEnumeration:]_block_invoke + 184
     9   CoreFoundation                      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
    

    Fixing these 'uncommited CATransactions' by forcing them to run on the main thread fixed the black camera issues. I was able to fix it by removing Option: NSEnumerationConcurrent from enumeration.

    The sample app which could constantly reproduce the problem can be downloaded here

    Hope the sample app could give some insight and the work around for the issue.

提交回复
热议问题