Search code examples
iosobjective-ciphoneuiimagepickercontrolleruiactionsheet

Captured image is not getting saved in the device


I have created two options in the screen.

  1. To capture the image from camera using : UIImagePickerControllerSourceTypeCamera
  2. To load the image from the UIImagePickerControllerSourceTypeSavedPhotosAlbum.

But when i am capturing the image, image is not storing in the device?

My code is:

-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{

    NSLog(@"From didDismissWithButtonIndex - Selected Option: %@", [actionSheet buttonTitleAtIndex:buttonIndex]);

    NSString*image=[actionSheet buttonTitleAtIndex:buttonIndex];

    if ([[actionSheet buttonTitleAtIndex:buttonIndex] isEqualToString:@"Camera"]) {

        if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
        {
            UIAlertView* alert = [[UIAlertView alloc] initWithTitle:nil message:@"Device Camera Is Not Working" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
            [alert show];
            return;
        }
        else{

            UIImagePickerController *picker = [[UIImagePickerController alloc] init];
            picker.delegate = self;
            picker.allowsEditing = YES;
            picker.sourceType = UIImagePickerControllerSourceTypeCamera;



            [self presentViewController:picker animated:YES completion:NULL];

        }
    }

    else if ([[actionSheet buttonTitleAtIndex:buttonIndex] isEqualToString:@"Gallery"])
    {
        UIImagePickerController *pickerView = [[UIImagePickerController alloc] init];
        pickerView.allowsEditing = YES;
        pickerView.delegate = self;
        [pickerView setSourceType:UIImagePickerControllerSourceTypeSavedPhotosAlbum];

        //[pickerView setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
        [self presentViewController:pickerView animated:YES completion:nil];

    }
}
#pragma mark - PickerDelegates

//=====================================Image picker ===============================================


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

    UIImage* orginalImage = [info objectForKey:UIImagePickerControllerOriginalImage];

    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:isRowIndex inSection:isSectionIndex] ;

    UITableViewCell *cell = [jobstable cellForRowAtIndexPath:indexPath];

    UIImageView *tableIMAGE=(UIImageView *)[cell.contentView viewWithTag:19];

    tableIMAGE.image=orginalImage;

    imageStris = [UIImageJPEGRepresentation(tableIMAGE.image,1)base64Encoding];

    answersARRAY[indexPath.row] = [NSString stringWithFormat:@"-1,%@,%@",answersARRAY[indexPath.row],imageStris];

    [self visubull];

    [self dismissViewControllerAnimated:YES completion:nil];

}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {

    [picker dismissViewControllerAnimated:YES completion:NULL];

}

Solution

  • Just put this line in - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ to store image

    When you capture image you have to store it manually.

    UIImageWriteToSavedPhotosAlbum(orginalImage,nil, nil, nil);
    

    Hope this will help you