如何获取ALAssetsLibrary保存的照片的网址?

时间:2014-09-11 12:55:39

标签: swift ios8 xcode6

我用ALIsetsLibrary的writeImageToSavedPhotosAlbum保存照片,在这个方法中我有一个在目标c中的完整块:

 ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];  
[library writeVideoAtPathToSavedPhotosAlbum:[NSURL fileURLWithPath:urlString]  
                            completionBlock:^(NSURL *assetURL, NSError *error) {  
                                if (error) {  
                                    NSLog(@"Save video fail:%@",error);  
                                } else {  
                                    NSLog(@"Save video succeed.");  
                                }  
                            }];  

}

但是当我在swift中显示它时,我得到一个对象:

 typealias ALAssetsLibraryWriteImageCompletionBlock = (NSURL!, NSError!) -> Void

我只想要获得NSURL 在Swift中我有完成Block的代码:

 var imageWriteCompletionBlock: ALAssetsLibraryWriteImageCompletionBlock!

 self.completionBlock = {
            reason in println(reason)
        }

怎么做呢?

谢谢!

1 个答案:

答案 0 :(得分:3)

ALAssetsLibrary().writeImageToSavedPhotosAlbum(image.CGImage, 
         orientation: ALAssetOrientation.fromRaw(image.imageOrientation.toRaw())!,     
     completionBlock:{ (path:NSURL!, error:NSError!) -> Void in
                           println("\(path)")
                     })

的问候,