swift ios when do I need to use mediaTypes kUTTypeImage
08:35 20 Sep 2016

I have a image picker in my app where you can select images from camera roll or take a new picture then upload the images to my backend server.

But looking around others code I see that some people use this: imagePickerController.mediaTypes = [kUTTypeImage as String]

Why do you need to set mediaTypes to kUTTypeImage?

I have not used that in my code bellow but everything still works fine

I select images like this through a UIAlertController:

//Check if camera exist
        if UIImagePickerController.isSourceTypeAvailable(.Camera) {
            let cameraAction = UIAlertAction(title: "Take a photo", style: .Default) { (action) in
                self.imagePicker.sourceType = .Camera
                self.imagePicked = 1
                self.presentViewController(self.imagePicker, animated: true, completion: nil)

            }

            alertController.addAction(cameraAction)
        }

        //Check if photo lib exist
        if UIImagePickerController.isSourceTypeAvailable(.PhotoLibrary) {
            let photosLibraryAction = UIAlertAction(title: "Pick image", style: .Default) { (action) in
                self.imagePicker.sourceType = .PhotoLibrary
                self.imagePicked = 1
                self.presentViewController(self.imagePicker, animated: true, completion: nil)

            }
            alertController.addAction(photosLibraryAction)
        }

Then I get the images:

 func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {


            if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
                //Change aspect when not dummy image
                self.bigImage.contentMode = .ScaleAspectFill
                self.bigImage.clipsToBounds = true
                self.bigImage.image = pickedImage
ios swift xcode image uiimagepickercontroller