【发布时间】:2016-08-17 05:30:09
【问题描述】:
我对 Swift 很陌生,我只是想获取我保存的照片的文件 URL。下面是一个小snippet inspired from this StackOverflow question
let imageData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(imageDataSampleBuffer)
// Save the photo to the album library
let image = UIImage(data: imageData)!
let orientation = ALAssetOrientation(rawValue: image.imageOrientation.rawValue)!
ALAssetsLibrary.writeImageToSavedPhotosAlbum(image.CGImage, orientation: orientation, completionBlock: {
(url: NSURL!, error: NSError!) -> Void in
if error != nil {
print(error)
} else {
// We have the URL here
}
})
但是,我一辈子都无法建造它。它显示以下错误:
无法使用参数列表调用“writeImageToSavedPhotosAlbum” 类型'(CGImage?,方向:ALAssetOrientation,completionBlock:(NSURL!, NSError!)-> 无效)'
它表明它期望:
需要一个类型为 '(CGImage!,orientation: ALAssetOrientation,完成块: ALAssetsLibraryWriteImageCompletionBlock!)'
我可以看到一个明显的问题是 CGImage 参数,但我不知道如何更改它,或者如果这是唯一的问题。有没有人看到这个或看到我的菜鸟错误是什么?
【问题讨论】:
标签: swift