AVCameraViewController.m从Apple示例代码更新到最新的iOS 11警告
我已经花了一个星期的时间来研究这个问题,慢慢地删除了由于Objective-C代码贬值而导致的警告和错误,而这些代码现在几乎可以正常工作了。我只收到了15条贬值警告 这段代码对我来说特别困难。甚至iOS 11.0的折旧率也在下降。我的意思是说AVCameraViewController.m从Apple示例代码更新到最新的iOS 11警告,ios,objective-c,Ios,Objective C,我已经花了一个星期的时间来研究这个问题,慢慢地删除了由于Objective-C代码贬值而导致的警告和错误,而这些代码现在几乎可以正常工作了。我只收到了15条贬值警告 这段代码对我来说特别困难。甚至iOS 11.0的折旧率也在下降。我的意思是说 1. JPEGPhotoDataRepresentationForJPEGSampleBuffer:previewPhotoSampleBuffer:' is deprecated: first deprecated in iOS 11.0 - Use -
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];
}
}];
});
-[AVCapturePhoto fileDataRepresentation]
。如果确实需要预览图像,请使用AVCapturePhoto.previewPixelBuffer
属性\u PreviewPhotosSampleBuffer
,它可能是此代码所在类的实例变量。当您访问一个实例变量时,实际执行的是self->\u previewPhotoSampleBuffer
。因为这需要self
,所以块会捕获它,可能会创建一个保留周期。编译器会警告您,因为如果不明确使用self
,您自己就不太可能注意到这一点。您可以通过执行self->\u previewPhotoSampleBuffer
使警告静音,但我认为对修复警告1所做的更改无论如何都会删除此代码\u previewPhotoSampleBuffer
已声明为CMSampleBufferRef*
(换句话说,是指向CMSampleBufferRef
的指针)。但是,CMSampleBufferRef
已经是一个指针。它是用于opaqueCMSampleBuffer*
的typedef。因此,将指向指针的指针传递到一个方法中,该方法需要一个指针,即CMSampleBufferRef
。无论在何处声明\u previewPhotoSampleBuffer
,都需要修复此问题这是否可以附加您的示例项目