Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AVCameraViewController.m从Apple示例代码更新到最新的iOS 11警告_Ios_Objective C - Fatal编程技术网

AVCameraViewController.m从Apple示例代码更新到最新的iOS 11警告

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 -

我已经花了一个星期的时间来研究这个问题,慢慢地删除了由于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];
        }
    }];
});
  • 由于对图像HEIC编解码器的新支持,iOS 11中不推荐使用JPEGPhotoDataRepresentationForJPEGSampleBuffer:PreviewPhotosSampleBuffer:方法。如警告所述,您应该改用
    -[AVCapturePhoto fileDataRepresentation]
    。如果确实需要预览图像,请使用
    AVCapturePhoto.previewPixelBuffer
    属性

  • 此警告是因为作为完成处理程序传递给captureStillImageAsynchronouslyFromConnection:connectionWithMediaType:completionHandler:的块使用了
    \u PreviewPhotosSampleBuffer
    ,它可能是此代码所在类的实例变量。当您访问一个实例变量时,实际执行的是
    self->\u previewPhotoSampleBuffer
    。因为这需要
    self
    ,所以块会捕获它,可能会创建一个保留周期。编译器会警告您,因为如果不明确使用
    self
    ,您自己就不太可能注意到这一点。您可以通过执行
    self->\u previewPhotoSampleBuffer
    使警告静音,但我认为对修复警告1所做的更改无论如何都会删除此代码

  • 似乎
    \u previewPhotoSampleBuffer
    已声明为
    CMSampleBufferRef*
    (换句话说,是指向
    CMSampleBufferRef
    的指针)。但是,
    CMSampleBufferRef
    已经是一个指针。它是用于
    opaqueCMSampleBuffer*
    的typedef。因此,将指向指针的指针传递到一个方法中,该方法需要一个指针,即
    CMSampleBufferRef
    。无论在何处声明
    \u previewPhotoSampleBuffer
    ,都需要修复此问题


  • 这是否可以附加您的示例项目