Я работаю над этим уже неделю, медленно удаляя предупреждения и ошибки, вызванные устареванием кода Objective-C, в том, что сейчас почти работает. Я до 15 предупреждений об износе.
Этот блок кода для меня особенно сложен. Он возвращает даже амортизацию для iOS 11.0. Я хочу сказать ...
1. JPEGPhotoDataRepresentationForJPEGSampleBuffer:previewPhotoSampleBuffer:' is deprecated: first deprecated in iOS 11.0 - Use -[AVCapturePhoto fileDataRepresentation] instead.
2. Block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior
Insert 'self->'
3. Incompatible pointer types sending 'CMSampleBufferRef *' (aka 'struct opaqueCMSampleBuffer **') to parameter of type 'CMSampleBufferRef _Nullable' (aka 'struct opaqueCMSampleBuffer *'); dereference with *
Replace '_previewPhotoSampleBuffer' with '*(_previewPhotoSampleBuffer)'
// Flash set to Auto for Still Capture
[CameraViewController setFlashMode:AVCaptureFlashModeAuto forDevice:[[self videoDeviceInput] device]];
// Capture a still image.
[[self stillImageOutput] captureStillImageAsynchronouslyFromConnection:[[self stillImageOutput] connectionWithMediaType:AVMediaTypeVideo] completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
if (imageDataSampleBuffer)
{
NSData *imageData = [AVCapturePhotoOutput JPEGPhotoDataRepresentationForJPEGSampleBuffer:imageDataSampleBuffer previewPhotoSampleBuffer:_previewPhotoSampleBuffer];
UIImage *image = [[UIImage alloc] initWithData:imageData];
[[[ALAssetsLibrary alloc] init] writeImageToSavedPhotosAlbum:[image CGImage] orientation:(ALAssetOrientation)[image imageOrientation] completionBlock:nil];
}
}];
});