AVCapture captureOutput никогда не вызывался в приложении-демоне iOS12 - PullRequest
0 голосов
/ 23 мая 2019

Я делаю приложение для получения фотографий без открытого приложения камеры ... на iOS12, если я устанавливаю приложение, например, как демон, или запускается вручную из папки / bin, не работает ... делегат

(void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection

никогда не вызывается (captureSessionDidStopRunning вызывается немедленно) ... есть подсказка?

Это моя ситуация (телефоны частично взломаны (рут без подложки):

iOS11

приложение установлено как ipa => работает

двоичный файл приложения установлен как демон => работает

iOS12

приложение установлено как ipa => работает

двоичный файл приложения установлен как демон => НЕ работает

и этот код:

- (void)setupCamera:(AVCaptureDevicePosition)position{
    LOG(@"setupCamera");

    NSArray *allTypes;
    if (@available(iOS 10.2, *)) {
        allTypes = @[AVCaptureDeviceTypeBuiltInDualCamera, AVCaptureDeviceTypeBuiltInWideAngleCamera, AVCaptureDeviceTypeBuiltInTelephotoCamera];

    } else {
         allTypes = @[AVCaptureDeviceTypeBuiltInWideAngleCamera, AVCaptureDeviceTypeBuiltInTelephotoCamera];
    }

    AVCaptureDeviceDiscoverySession *discoverySession = [AVCaptureDeviceDiscoverySession discoverySessionWithDeviceTypes:allTypes
                                                                                                               mediaType:AVMediaTypeVideo
                                                                                                                position:AVCaptureDevicePositionUnspecified];
    AVCaptureDevice *device = nil;

    for (AVCaptureDevice *d in discoverySession.devices) {
        if([d position] == position) {
            device = d;
            break;
        }
    }

    if (!device) {
        LOG(@"Camera not found!");
        return;
    }

    AVCaptureDeviceInput* input = [AVCaptureDeviceInput deviceInputWithDevice:device error:nil];
    AVCaptureVideoDataOutput* output = [[AVCaptureVideoDataOutput alloc] init];
    output.alwaysDiscardsLateVideoFrames = YES;

    dispatch_queue_t queue;
    queue = dispatch_queue_create("cameraQueue", NULL);
    [output setSampleBufferDelegate:self queue:queue];
    NSDictionary* videoSettings = @{(NSString *) kCVPixelBufferPixelFormatTypeKey:[NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA]};
    [output setVideoSettings:videoSettings];

    self.captureSession = nil;
    self.captureSession = [[AVCaptureSession alloc] init];

    if ([self.captureSession canAddInput:input] && [self.captureSession canAddOutput:output]) {
        [self.captureSession addInput:input];
        [self.captureSession addOutput:output];
    }

    [self.captureSession setSessionPreset:AVCaptureSessionPresetHigh];

    self.previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:self.captureSession];
    self.previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;

    [self.captureSession startRunning];
}
...