简体   繁体   English

将图像保存在iOS相册(我的文件夹)中,并保存图像URL

[英]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. 要点是使用ALAssetsLibrarywriteImageToSavedPhotosAlbum:orientation:completionBlock:方法。

It's always nice to learn. 总是很高兴学习。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在iOS7中将图像保存到自定义相册 - saving image to custom photo album in iOS7 如何在不将图像保存到相册的情况下发布到我的Facebook墙上 - How to post to my Facebook wall without saving the image to a photo album 图像未保存到iPad mini中的相册 - Image is not saving to Photo album in iPad mini 写入iOS相册的图像不正确 - Incorrect image written to iOS photo album 将图像保存在App Directory中而不是转到相册。 Objective C iOS - Saving an Image in App Directory instead of going to photo album. Objective C iOS 将 JPG 图像从文档保存到相册 - 示例代码 - Saving JPG image from Documents to Photo Album - Sample Code iOS:如何将当前UIView中的当前图像保存到相册? 我被UIImageWriteToSavedPhotosAlbum困住了 - iOS : How to save current image from my current UIView to photo album? I'm stuck with UIImageWriteToSavedPhotosAlbum 将图像保存到特定的相册,但限制保存到相机胶卷文件夹中 - Save image to a specific photo album, but restrict to save into camera roll folder 尝试在 iOS 中使用自定义名称将图像保存到相册 - Trying to save image to Photo album with custom name in iOS iOS - 如何实现裁剪图像,如默认相册? - iOS - how to implement crop image like default photo album?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM