Im am trying to capture images and save them to a custom album using UIImagePickerController.TMy problem is that the images are getting saved into the following albums
1) My custom album
2)Camera Roll
3) My Photo Stream
I am using the following code for the image saving part
//Save image in an album with the app's name
_assetsLibrary = [[ALAssetsLibrary alloc] init];
[_assetsLibrary saveImage:imageToSave toAlbum:#"My Album" withCompletionBlock:^(NSError *error) {
if (error!=nil) {
DLog(#"Big error: %#", [error description]);
}
}];
How can i prevent the photos from getting saved as multiple copies??
Related
I am trying to create a collection list in Photos which will have multiple albums.
The code to create the collection list is as follows:
__block NSString * localId;
NSError *createFolderError;
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
// Create the folder
PHCollectionListChangeRequest *changeRequest = [PHCollectionListChangeRequest creationRequestForCollectionListWithTitle: #"My Photos"];
localId = [[changeRequest placeholderForCreatedCollectionList] localIdentifier];
} completionHandler:^(BOOL success, NSError * _Nullable error) {
if (!success) {
DebugLog(#"Creating My Photos Folder Failed... error : %#", error.description);
return;
}
if(localId) {
//Do something
}
}];
But, getting error as follows:
Error Domain=NSCocoaErrorDomain Code=-1 "(null)"
Earlier, it was creating folder even after getting the error, but now, I see folder not getting created under Photos application.
Let me know if I am doing anything wrong.
EDIT
The folder is getting created in the Photos app each time, but was not reflecting. When Photos App was killed and relaunched, I can see the folder. But still, why the error is shown, remains a question.
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. My question is, How do i get that photo album image url after saving the image?
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. 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.
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. In this case you might e.g. give them a name that serves as key to identify each image.
EDIT
As #MidhunMP commented, I was wrong on that! 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.
The main point is to use ALAssetsLibrary's writeImageToSavedPhotosAlbum:orientation:completionBlock: method.
It's always nice to learn.
I'm trying to save a video made in an app to a custom album.
I've tried the solution proposed on Saving Video in an Album Created, however, these blocks are executed asynchronously resulting in my asset in the result block being nil.
I've succeeded in creating the album, writing a video to it doesn't seem to work with the above methods. I have no clue what's going on. Can someone give me a heads up on this?
The url you got is a file url but not an ALAsset url.
You'll need to save that mov to camera roll first and add its asset reference to the custom album.
Check out the example code in this tutorial.
http://www.touch-code-magazine.com/ios5-saving-photos-in-custom-photo-album-category-for-download/
for video saving support, just add the function below to the category offered here:
http://www.touch-code-magazine.com/ios5-saving-photos-in-custom-photo-album-category-for-download/
-(void)saveVideoLocalUrl:(NSURL*)assetURL toAlbum:(NSString*)albumName withCompletionBlock:(SaveImageCompletion)completionBlock
{
//add the asset to the custom photo album
[self writeVideoAtPathToSavedPhotosAlbum:assetURL completionBlock:^(NSURL *assetURL, NSError *error) {
NSLog(#"error: %#", [error description]);
[self addAssetURL: assetURL
toAlbum:albumName
withCompletionBlock:completionBlock];
}];
}
I have an image and i want to save that image into custom photo album.
My code is working fine for Iphone but it is not workin for iPad.
self.library = [[ALAssetsLibrary alloc] init];
[self.library saveImage:imageShow.image toAlbum:#"APP NAME" withCompletionBlock:^(NSError *error) {
if (error!=nil) {
NSLog(#"Big error: %#", [error description]);
}
}];
just help me please
Thanx for help..
I want to save a image captured with AVCaptureStillimageOutput and I'm trying to save it using this code :
[self.library writeImageToSavedPhotosAlbum:image metadata:nil completionBlock:nil]:
it's by default saving to PhotoRoll and there is no option to change album.
I found an older guide o how to save image to album using this code:
[self.library saveImage:img toAlbum:albumName withCompletionBlock:^(NSError *error) {
if (error!=nil) {
NSLog(#"Big error: %#", [error description]);
}
}];
but it seems to be deprecated... Is it possible to make it nondeprecated because i think that this method is the one I'm looking for.
All photos go to the SavedPhotos. Once you saved it there you can use the library method
addAssetsGroupAlbumWithName:resultBlock:failureBlock:
and then the ALAssetsGroup method
addAsset:
Please see this answer for more detail:
Create, Delete, and add pictures to albums in the photos app?