Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Choose Image from gallery

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 660
    Comment on it

    Hi All,

    Sometime we have to pick an image/video from device gallery and to open gallery/photos of your device and pick any image , we have to follow these simple steps.

     

    1) Ask permission to access user gallery. Add these key and value in your project plist:-

     <key>NSPhotoLibraryUsageDescription</key>
     <string>This app requires access to the photo library.</string>

     

    2) Add code to open image gallery:-

    if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.savedPhotosAlbum){
                
                let imagePicker = UIImagePickerController()
                imagePicker.delegate = self
                imagePicker.sourceType = UIImagePickerControllerSourceType.savedPhotosAlbum
                imagePicker.allowsEditing = false
                self.present(imagePicker, animated: true, completion: nil)
            }

     

    3) Last step to use the chose image by user :-

    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
            print(info)
    //you can use image in data variable as this image is one which user picked from gallery. 
            let data = UIImagePNGRepresentation(info[UIImagePickerControllerOriginalImage] as! UIImage)
            
        }

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: