只使用相机拍摄的照片,iOS/Swift

Only use pictures taken through the camera, iOS/Swift

我正在尝试编写一个功能,用户可以使用该功能将照片上传到我的服务器。不过,我想禁止用户从相册中选择图片。无论如何我可以使用 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)
}

您可以将 sourceType 设置为 camera 以仅将图像选择器作为相机打开。

@IBAction func pictureButtonTapped(sender: AnyObject) {
    let imagePickerController = ImagePickerController()
    imagePickerController.imageLimit = 1
    imagePickerController.delegate = self

    // Add these lines

    imagePickerController.sourceType = .camera

    presentViewController(imagePickerController, animated: true, completion: nil)
}
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) {}
    }