[英]Saving image in iOS photo album(my folder) and have the image url stored
I want to save an image (which is downloaded from server) in iOS device photo album and store that image photo album url in local database. 我想将图像(从服务器下载)保存在iOS设备相册中,并将该图像相册的URL存储在本地数据库中。 My question is, How do i get that photo album image url after saving the image?
我的问题是,保存图像后如何获取该相册的图像URL?
I am able to save the image in photo album using the following ALAsset code: But, I need this url image also to be stored in my local db. 我可以使用以下ALAsset代码将图像保存在相册中:但是,我还需要将此url图像存储在本地数据库中。 So next time, i won't download the same image from server and i can load directly from device photo album.
因此,下次,我将不会从服务器下载相同的图像,并且可以直接从设备相册中加载。
[self.maAssetsLibrary saveImage:image
toAlbum:@"My-Album"
completion:completion
failure:nil];
Please suggest. 请提出建议。
UPDATE: I tried this, but NOT getting me the photo album image URL after saving the image. 更新:我尝试过此操作,但保存图像后没有得到相册图像URL。
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// The completion block to be executed after image taking action process done
void (^completion)(NSURL *, NSError *) = ^(NSURL *assetURL, NSError *error) {
};
[self.maAssetsLibrary saveImage:image toAlbum:@"My-Album" completion:^(NSURL *assetURL, NSError *error){
if (error) {
NSLog(@"error");
} else {
NSLog(@"url %@", assetURL);
}
} failure:^(NSError *error) {
}];
}); });
Due to sandboxing you can't get such a url. 由于沙箱,您无法获得这样的网址。 As @Lord Zsolt proposes in the comment, you can overcome this by saving images in your application's folder.
正如@Lord Zsolt在评论中建议的那样,您可以通过将图像保存在应用程序的文件夹中来解决此问题。 In this case you might eg give them a name that serves as key to identify each image.
在这种情况下,您可以例如给他们起一个名字,作为识别每个图像的关键。
EDIT 编辑
As @MidhunMP commented, I was wrong on that! 正如@MidhunMP所评论的那样,我错了! There is a way (and I'm happy to know that now) and it comes from this Stack Overflow answer , provided by @CRDave in the comment above.
有一种方法(现在我很高兴知道),它来自@CRDave在上面的注释中提供的Stack Overflow答案 。
The main point is to use ALAssetsLibrary
's writeImageToSavedPhotosAlbum:orientation:completionBlock:
method. 要点是使用
ALAssetsLibrary
的writeImageToSavedPhotosAlbum:orientation:completionBlock:
方法。
It's always nice to learn. 总是很高兴学习。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.