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];
}];
}
Related
I have an application that deletes photos from the camera roll. This wipe is initiated remotely. Due to this if a wipe is initiated and the user is not at their phone they it will not wipe because you need to authorize the delete for each image.
Now I've read this is not possible in different questions. However, is it possible to request authorization to the phones photo library just as is done with geolocation when the application finishes loading on the first launch. Would this grant authorization for deleting without the need to confirm for every photo?
This is how I'm currently deleting the photos, it works fine apart from the need to confirm deletion of every image
PHFetchResult *asset = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:nil];
[asset enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
NSLog(#"%#",[obj class]);
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
BOOL req = [obj canPerformEditOperation:PHAssetEditOperationDelete];
if (req) {
NSLog(#"true");
[PHAssetChangeRequest deleteAssets:#[obj]];
}
} completionHandler:^(BOOL success, NSError *error) {
NSLog(#"Finished Delete asset. %#", (success ? #"Success." : error));
if (success) {
NSLog(#"WIPE SUCCESSFUL");
}
}];
}];
It's not possible to delete any photos/videos through the provided APIs without the confirmation alert. There is no way around this.
The app requests authorization for photo to get access permissions to the photos. This permission is to get photos (application can copy all the photos in the device, do you want any app could do so?), not to delete them.
If you want to delete some asset or collections you have to receive specific authorization from the user each time. You can do some changes together with request authorization only once - but you have to contact with the user at least once about this.
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.
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??
I have created a custom album with using the below code
(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
<--other code stuffs here-->
<--selectedImage is the UIImage from Camera or from gallery-->
[self.library saveImage:selectedImage toAlbum:#"My Album" withCompletionBlock:^(NSError *error)
{
if (error!=nil)
{
NSLog(#"Big error: %#", [error description]);
}
}];
<--other code stuffs here-->
}
Now I want to display these saved images in my application.
How do I access these images, and create a gallery in my APP.
Thanks,
Sujith
The method you want is the ALAssetsLibrary method addAssetsGroupAlbumWithName:resultBlock:failureBlock: which is detailed in the docs here: http://developer.apple.com/library/ios/#documentation/AssetsLibrary/Reference/ALAssetsLibrary_Class/Reference/Reference.html#//apple_ref/occ/cl/ALAssetsLibrary
It was introduced in iOS 5 and has not since been deprecated, so I'm not quite sure what the issue is if it's not working for you. You may have to update or repost the question if you are having trouble with it.
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?