我正在做一个用于在没有打开相机应用程序的情况下获取照片的应用程序……在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];
}