Create, Delete, and add pictures to albums in the photos app? - iphone

Haven't seen anything, but I have seen that you can create albums in the iOS 5 photos.app, and I was curious if there is a way to integrate it in my app.
I need to be able to create the album, upload pictures to it, and be able to delete it.
Thanks,
Coulton

Since iOS5 you can programmatically add albums to Photos. See the ALAssetsLibrary Class Reference.
You can add an album (which is an ALAssetsGroup) with:
addAssetsGroupAlbumWithName:resultBlock:failureBlock:
Every ALAssetsGroup has a URL associated with it. You'll want to save it:
valueForProperty:ALAssetsGroupPropertyURL
You can then use that URL to get an ALAssetsGroup object:
groupForURL:resultBlock:failureBlock:
Once you have your ALAssetsGroup you can use addAsset: method on it to add an image or video.
Notice: all these methods are asynchronous and return immediately. You do the actual work in the blocks you pass to these methods.

See the UIImage class reference:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImage_Class/Reference/Reference.html
void UIImageWriteToSavedPhotosAlbum (
UIImage *image,
id completionTarget,
SEL completionSelector,
void *contextInfo
);
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIKitFunctionReference/Reference/reference.html#//apple_ref/c/func/UIImageWriteToSavedPhotosAlbum
Adds to the camera roll album (camera) or saved photos album (no camera).

Related

Can i save photos to the camera roll without user explicit consent?

i'm developing an iPhone application that let users to take photos. Those photos are saved inside the application, but i would like also to save them to the camera roll.
The problem is that my application does not have a UI control that let the user specify if he wants the photo to be saved also in the camera roll.
I searched the Apple guidelines and documentation but could not find any hint regarding this issue.
So in your experience is ok to save photos taken by the user also in the camera roll without asking his permission?
It is perfectly fine to write to camera roll without permission..but it is better to show a successful save alert once you save photo.. user won't be happy if you are saving unnecessary/involuntary photo without some feedback to user
void UIImageWriteToSavedPhotosAlbum (
UIImage *image,
id completionTarget,
SEL completionSelector,
void *contextInfo
);
above is the method to save the image .. it can be find in apple docs here Save to camera roll
If the user is taking the photo himself by tapping a button or whatever, saving to the camera roll is the best you could do, IMO, and I don't think you need to show an alert or whichever kind of notice.
The only thing, make sure the user knows where he should go to retrieve his pictures...

iOS - Cached data used by ALAssetsLibrary is not updated

I seem to be having caching issues with the ALAssetLibrary when testing my app on the iPhone.
Steps used to produce this issue
Take a photo using the iPhone camera
Access the Camera Roll using ALAssetsLibrary (through ELCImagePicker)
The problem is that when ELCImagePicker displays the list of albums, the thumbnail of the photo taken in step 1 is displayed for the Camera Roll album (which is correct), but when I go into the Camera Roll album, that photo is not there. An error like this is also displayed in the console log:
Cached count is off for 0x2391d0 <x-coredata://D226A7C3-95D5-40B3-BCFB-726E534AB57A/Album/p1> (1357 != 1358) moc=<PLManagedObjectContext: 0x63794c0>
1357 and 1358 appears to be match the photo count before and after I take the photo, and closing the image picker and opening it again doesn't help. But if I switch to the Photos app, the photo is displayed there. And when I return to my app, the photo is now displayed as well.
I have tried both
UIImageWriteToSavedPhotosAlbum ( UIImage *image, id completionTarget, SEL completionSelector, void *contextInfo );
and ALAssetsLibrary's
(void)writeImageToSavedPhotosAlbum:(CGImageRef)imageRef orientation:(ALAssetOrientation)orientation completionBlock:(ALAssetsLibraryWriteImageCompletionBlock)completionBlock
but neither works. Any help is greatly appreciated. Thanks!
You can listen for ALAssetsLibraryChangedNotification notification.
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(reloadAlbumGroups) name:ALAssetsLibraryChangedNotification object:nil];
In reloadAlubmGroups load your album groups from assets library to get updated objects.
Apple Documentation:
ALAssetsLibraryChangedNotification
Sent when the contents of the assets library have changed from under the app that is using the data.
When you receive this notification, you should discard any cached information and query the assets library again. You should consider invalid any ALAsset, ALAssetsGroup, or ALAssetRepresentation objects you are referencing after finishing processing the notification.
In iOS v4.0, the notification’s object is nil. In iOS v4.1 and later, the notification object is the library object that posted the notification.

Saving UIImage as PNG to photo album on iPhone

I am merging some png files to a uiimage and I followed this thread ( UIImageWriteToSavedPhotosAlbum save as PNG with transparency? )
and tried to save the result as a png file by replacing this code with my image: [self composeImageWithWidth:100 andHeight:100)..
When I test this using simulator, I go to the folder in application support and find the png there. However when I test this on a real device, I cannot find the png file in my photo album.
What could be going wrong?
Perhaps the paths of photo album?
Thanks for the answers
You can use this function:
UIImageWriteToSavedPhotosAlbum(UIImage *image, id completionTarget, SEL completionSelector, void *contextInfo);
You only need completionTarget, completionSelector and contextInfo if you want to be notified when the image is done saving, otherwise you can pass in nil.
More info here

iPhone rewrite image file

I would like to access an image file in the iPhone images directory.
Then I would like to open this file as binary and be able to rewrite it.
Assuming user has chosen this file using the UIImagePickerController, is it possible to do such thing using iPhone API?
http://developer.apple.com/library/ios/#DOCUMENTATION/AudioVideo/Conceptual/CameraAndPhotoLib_TopicsForIOS/Articles/PickinganItemfromthePhotoLibrary.html this tutorial will help you in getting UIImage from photo library.
Once you obtain the image, you can do custom modifications to the UIImage and save it to photo album using this API:
Adds the specified image to the user’s Camera Roll album.
void UIImageWriteToSavedPhotosAlbum (
UIImage *image,
id completionTarget,
SEL completionSelector,
void *contextInfo
);
If you are looking to replace the existing photo from Photo library , there is no direct (or Apple Approved) way to do that. If you still want to do that, you can find path to photo library (/private/var/mobile/Media/DCIM/100APPLE) and try rewriting the photos.

Retrieving an iPhone photo saved to the photo library

I am saving images to the photo library and would like to retrieve them dynamically to display in future launches of my app. I use the WriteToSavedPhotosAlbum function, as below, but do not get any info to access the saved photo programmatically.
UIImageWriteToSavedPhotosAlbum(UIImage *image, id completionTarget, SEL completionSelector, void *contextInfo);
Once saved, is there a way to retrieve the file name/id and load an image from the photo library at a later time?
You just need to save them for yourself.
Possibly in your app's documents or cache folder.
As a side note, when you say: "display at launch", if you mean to replace the Default.png, that won't work.
The launch image must be static and included in your app bundle.
If not, disregard.
You can't, unless the user picks the photo using the UIImagePickerController.
Check this related question
try this code segment make the necessay changes
UIImagePickerController *picker=[[UIImagePickerController alloc] init];
picker.delegate=pickerDelegate;
picker.sourcetype=UIImagepickerControllerSourceTypePhtoLibrary;