我需要知道,如果图像已经在iOS的画廊。 我正在开发一个消息客户端应用程序,并在我的聊天列表中,我能够下载传入消息的图像/视频当我点击进入图片缩略图。
问题是,当我在缩略图挖掘,我下载并保存该图像插入iOS照片库,但如果我再次点击我不想再次下载并保存它,我想从照片库检索。
恢复,我想看看在照片库中的图像,并检索。
这里是我的代码保存图像使用ALAssetsLibrary我的自定义相册:
[self writeImageToSavedPhotosAlbum:image.CGImage orientation:(ALAssetOrientation)image.imageOrientation completionBlock:
^(NSURL* assetURL, NSError* error)
{
if (error!=nil) {
completionBlock(error);
return;
}
//add the asset to the custom photo album
[self addAssetURL: assetURL
toAlbum:albumName
withCompletionBlock:completionBlock];
}
];
-(void)addAssetURL:(NSURL*)assetURL toAlbum:(NSString*)albumName withCompletionBlock:(SaveImageCompletion)completionBlock
{
__block BOOL albumWasFound = NO;
[self enumerateGroupsWithTypes:ALAssetsGroupAlbum
usingBlock:
^(ALAssetsGroup *group, BOOL *stop)
{
if ([albumName compare: [group valueForProperty:ALAssetsGroupPropertyName]]==NSOrderedSame) {
albumWasFound = YES;
[self assetForURL: assetURL
resultBlock:
^(ALAsset *asset)
{
//add photo to the target album
[group addAsset: asset];
completionBlock(nil);
} failureBlock: completionBlock
];
return;
}
if (group==nil && albumWasFound==NO) {
//Target album does not exist, create it
__weak ALAssetsLibrary* weakSelf = self;
[self addAssetsGroupAlbumWithName:albumName
resultBlock:
^(ALAssetsGroup *group)
{
[weakSelf assetForURL: assetURL
resultBlock:
^(ALAsset *asset)
{
//add photo to the newly created album
[group addAsset: asset];
completionBlock(nil);
} failureBlock: completionBlock
];
} failureBlock: completionBlock
];
return;
}
} failureBlock: completionBlock
];
}
也许与assetURL我能做到这一点,但我苹果的文档中一直在寻找,我没有看到任何东西。
谢谢!!