仅使用通过相机拍摄的照片,iOS / Swift

时间:2016-10-24 10:19:17

标签: ios swift uiimagepickercontroller

我正在尝试编写一个用户可以使用的功能,并将pic上传到我的服务器。我想禁止用户从Photo Roll中选择一张照片。无论如何我可以使用ImagePicker pod做到这一点吗?

multipartEntityBuilder.addPart(FormBodyPartBuilder.create().setName(propName).setBody(new StringBody(propValue, ContentType.create("application/octet-stream", "UTF-8"))).build());
multipartEntityBuilder.addPart(propName, new StringBody(propValue, ContentType.create("application/octet-stream", "UTF-8")));

2 个答案:

答案 0 :(得分:1)

您可以将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)
}

答案 1 :(得分:0)

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) {}
    }