0

I want to saved an image in my photo albums, however I had succesfully saved the image but now I want to get the URL which would be my local URL that would open the image If I passes that to UIImage. I'm unable to get the saved image url as of error that "expression not allowed". How can I get the LOCAL URL of my saved image in iOS.

My Tried:

-(NSString *) imageSave: (UIImage *)image
{
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];

        [library writeImageToSavedPhotosAlbum:image.CGImage orientation:(ALAssetOrientation)image.imageOrientation completionBlock:^(NSURL *assetURL, NSError *error )
         {
             [library assetForURL:assetURL resultBlock:^(ALAsset *asset )
              {
                  self.temp1 = [NSString stringWithFormat:@"%@",assetURL];
                  NSLog(@"SAVED!");
              }
                     failureBlock:^(NSError *error )
              {
                   self.temp1 = [NSString stringWithFormat:@"NO"];
                  NSLog(@"Error Saving Image!!!");
              }];
         }];

    return self.temp1;
}

I tried by ma making a property but that returns null.

developer
  • 668
  • 1
  • 6
  • 24

1 Answers1

0

Try following code that may help you.

UIImage *viewImage = YOUR UIIMAGE  // --- 
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];  
// Request to save the image to camera roll  
[library writeImageToSavedPhotosAlbum:[viewImage CGImage] orientation:(ALAssetOrientation)[viewImage imageOrientation] completionBlock:^(NSURL *assetURL, NSError *error){  
    if (error) {  
        NSLog(@"error");  
    } else {  
            NSLog(@"url %@", assetURL);
        NSString *myString = [assetURL absoluteString];

    }  
}];  
Piyush
  • 1,534
  • 12
  • 32