Rutger Huijsmans Rutger Huijsmans - 1 year ago 127
iOS Question

Only use pictures taken through the camera, iOS/Swift

I'm trying to write a function with which the user can take and upload upload a pic to my server. I want to disallow users from selecting a picture from the Photo Roll though. Is there anyway I can do this using the ImagePicker pod?

func cancelButtonDidPress(imagePicker: ImagePickerController) {
imagePicker.dismissViewControllerAnimated(true, completion: nil)

func wrapperDidPress(imagePicker: ImagePickerController, images: [UIImage]) {

func doneButtonDidPress(imagePicker: ImagePickerController, images: [UIImage]) {
imagePicker.dismissViewControllerAnimated(true, completion: nil)

@IBAction func pictureButtonTapped(sender: AnyObject) {
//take picture
let imagePickerController = ImagePickerController()
imagePickerController.imageLimit = 1
imagePickerController.delegate = self
presentViewController(imagePickerController, animated: true, completion: nil)

Answer Source
import DKImagePickerController

@IBAction func pictureButtonTapped(sender: AnyObject) {
        let pickerController = DKImagePickerController()

        pickerController.didSelectAssets = { (assets: [DKAsset]) in
            let size = CGSizeMake(512, 512)
            assets[0].fetchImageWithSize(size, completeBlock: { image, info in
                self.image = image
                self.pictureButton.setBackgroundImage(self.image, forState: .Normal)

        pickerController.singleSelect = true
        pickerController.maxSelectableCount = 1
        pickerController.sourceType = .Camera

        self.presentViewController(pickerController, animated: true) {}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download