0

I have a button to capture picture then it save to photoAlbum. I used another button for load image from using imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; then i implemented didFinishPickingMediaWithInfo: for loading photo album to newImage. My need is after capture photo i have alertview then click YES button automatically load last captured image PhotoAlbum and add newImage. Is it possible?

- (void)saveImageToPhotoAlbum
{

    [self.library saveImage:[self  stillImage] toAlbum:@"Album" withCompletionBlock:^(NSError *error) {
        if (error!=nil) {
            NSLog(@"Big error: %@", [error description]);
        }
    }];


    UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Gallery"
                                                        message:@"Do you want to use the captured image?" delegate:self
                                              cancelButtonTitle:@"Cancel" otherButtonTitles:@"Yes", nil];


    alertView.tag = 2;
    [alertView show];


}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    //set image


    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {



        newImage = [[UIImageView alloc] initWithImage:[info objectForKey:UIImagePickerControllerOriginalImage]];

        [newImage setFrame:CGRectMake(0, 0, 320, 568)];

       [self.view addSubView:newImage];
}

I need to display last captured image to newImage click of alertView button:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    // the user clicked one of the OK/Cancel buttons

     if (buttonIndex == 1){

}
}
user3496826
  • 101
  • 2
  • 14

1 Answers1

0
 Before use below code take UIImage *img in .h file   

     - (void)saveImageToPhotoAlbum
        {

            [self.library saveImage:[self  stillImage] toAlbum:@"Album" withCompletionBlock:^(NSError *error) {
                if (error!=nil) {
                    NSLog(@"Big error: %@", [error description]);
                }
            }];


            UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Gallery"
                                                                message:@"Do you want to use the captured image?" delegate:self
                                                      cancelButtonTitle:@"Cancel" otherButtonTitles:@"Yes", nil];


            alertView.tag = 2;
            [alertView show];


        }

        -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
            //set image
        img=nil;
        img=[info objectForKey:UIImagePickerControllerOriginalImage];
        [self saveImageToPhotoAlbum];
//        [self dismissViewControllerAnimated:YES completion:nil];
    }

    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
    {

        if (buttonIndex == 1)
       {

             if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {

                        if(newImage)
                        {
                             [newImage removeFromSuperview];
                              newImage=nil;
                        }
                        newImage = [[UIImageView alloc] initWithImage:img];

                        [newImage setFrame:CGRectMake(0, 0, 320, 568)];

                       [self.view addSubView:newImage];
             }
             [picker dismissViewControllerAnimated:YES completion:nil];
        }
        else
        {
          img=nil;
          [picker dismissViewControllerAnimated:YES completion:nil];
        }
    }
Bipin Patel
  • 228
  • 1
  • 5