iPhone auto sync photos with our application using AlAssetLibrary
I have just started developing an application in which I want to auto sync all the images stored in user's photo library as assets.
I am able to get URL for images those are stored as assets.
e.g. assets-library://asset/asset.JPG?id=1000000003&ext=JPG
Now开发者_StackOverflow社区, how do I copy this image in to document's directory of my application or how do I just display image stored in assets by getting that in NSData
or in UIImage
?
Thanks in Advance.
You can use the following code in UIImagePickerControllerDelegate
delegate implementation
- (void) imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
//obtaining saving path
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *imagePath = [documentsDirectory stringByAppendingPathComponent:@"my_photo.png"];
//extracting image from the picker and saving it
UIImage *editedImage = [info objectForKey:UIImagePickerControllerEditedImage];
NSData *imageData = UIImagePNGRepresentation(editedImage);
[imageData writeToFile:imagePath atomically:YES];
}
精彩评论