How To Pick A Photo From Any Albums In iOS Programmatically

The UIImagePickerController is a powerful tool provided by Apple in Objective-C. You can use this Controller for uploading photo or transferring photos from a certain album to another. I have here a sample source code on how to use UIImagePickerController. This code allows you to pick a photo and use it for passing the photo to image editor inside your app, or uploading it to a certain website.

SOURCE TYPE: PHOTO ALBUM

UIImagePickerController *picker =   [[UIImagePickerController alloc] init];

    picker.sourceType               =   ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) ? UIImagePickerControllerSourceTypePhotoLibrary : UIImagePickerControllerSourceTypeCamera;

    picker.delegate                 =   self;

   picker.allowsEditing            =   YES;

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


SOURCE TYPE: CAMERA

    NSLog(@"photo button has been clicked");
    
    photoButtonClicked = true;
    
    UIImagePickerControllerSourceType type = UIImagePickerControllerSourceTypeCamera;
    
    if([UIImagePickerController isSourceTypeAvailable:type]){
        
        UIImagePickerController *picker = [self photoPicker];
        //picker.allowsEditing = NO;
        
        
        //picker.delegate   = self;
        
        //picker.sourceType = type;
        
        
        [self presentViewController:picker animated:YES completion:nil];
    }

The code above allows you to load or present the iOS Photo Camera, easy right? It will pop up (presentViewController) the built in camera and will automatically save the asset into your (by default) Camera Roll.

That would be all guys! Please subscribe! Cheers! If you have clarifications, post it on the comment box below the post.

Post a Comment