IOS saves the picture to the album and gets an instance of the image file name


Examples are as follows:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
 UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
 if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {
- (void)image:(UIImage*)image didFinishSavingWithError:(NSError*)error contextInfo:(void*)contextInfo
 if (error) {
  Dlog (@ "picture save failed! "";
  Dlog (@ "picture saved successfully! "";
This method can save pictures from other sources to the album

 //When the image is obtained from the camera, it is stored in the album
 //Preservation method 1
//  UIImageWriteToSavedPhotosAlbum(img.image,self,@selector(image:didFinishSavingWithError:contextInfo:),NULL);
//   imageData = nil;
  //Save method 2 at the same time get the saved photo file name
  __blockALAssetsLibrary *lib = [[ALAssetsLibraryalloc] init];
  [lib writeImageToSavedPhotosAlbum:img.image.CGImagemetadata:nilcompletionBlock:^(NSURL *assetURL,NSError *error) {
   ALAssetsLibraryAssetForURLResultBlock resultblock = ^(ALAsset *imageAsset)
    ALAssetRepresentation *imageRep = [imageAssetdefaultRepresentation];
    weakSelf.imageName = [NSStringstringWithFormat:@"%@",[imageRepfilename]];
    NSLog(@"[imageRep filename 1] : %@", [imageRepfilename]);
    DBLog(@" self.addressImageName Photo 0 =% @ ", weakSelf.imageName );
   ALAssetsLibrary* assetslibrary = [[ALAssetsLibraryalloc] init];
   [assetslibrary assetForURL:assetURLresultBlock:resultblock failureBlock:nil];
   NSLog(@"assetURL = %@, error = %@", assetURL, error);
   lib = nil;

The above example of IOS saving pictures to an album and getting the image file name is all the content that Xiaobian shares with you. I hope it can give you a reference, and I hope you can support developeppaer more.

Recommended Today

Choose react or angular 2

Original addressChoosing between React vs. Angular 2The following is the translation of this article, which can be used at your choiceReactperhapsAngular2We need to help when we need to. React has become a cool representative in 2015, but angular.js has changed from a front-end framework that people love to a terrible devil (and not so terrible…) […]