Ios ALAssetLibrary能否加载文档文件夹中的图像文件?

Ios ALAssetLibrary能否加载文档文件夹中的图像文件?,ios,metadata,alassetslibrary,Ios,Metadata,Alassetslibrary,ALAssetLibrary可以很容易地从相机卷或相册中获取图像文件信息。但是,当我尝试使用它加载文档文件夹(沙盒)中的图像文件时,它总是一无所获。这是我的代码: //Get full file path in the Document folder.(Yes, IMG001.jpg exists in that place) NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomai

ALAssetLibrary可以很容易地从相机卷或相册中获取图像文件信息。但是,当我尝试使用它加载文档文件夹(沙盒)中的图像文件时,它总是一无所获。这是我的代码:

//Get full file path in the Document folder.(Yes, IMG001.jpg exists in that place)
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* theFileName = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"IMG001.jpg"];
NSURL* theFileURL = [NSURL fileURLWithPath:theFileName];

//Now try to load the asset.
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library assetForURL:theFileURL resultBlock:^(ALAsset *asset) {
    //asset here is always nil.
} failureBlock:^(NSError *error) {
    //it does not run in this place.
}];

有人能告诉我原因吗?

传递给assetForURL函数的url应该是以前从ALAsset对象检索到的资产url。对象表示由照片应用程序管理的照片或视频。因此,在这种情况下不能使用ALAssetLibrary

要从文档目录获取图像,请使用以下命令:

    NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString* imageFilePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"IMG001.jpg"];
    UIImage* imageRequired = [UIImage imageWithContentsOfFile: imageFilePath];

谢谢但是UIImage不包含元数据。事实上,我的目的是将我的照片与元数据一起保存到相机卷中。这可以通过ALAssetLibrary writeImageToSavedPhotosAlbum:metadata:completionBlock:的方法完成。所以,我的目标是元数据。我想通过ALAssetLibrary获取元数据。