gpt4 book ai didi

ios - 如何使用 UIImagePickerController 从实际设备访问照片

转载 作者:行者123 更新时间:2023-11-29 02:20:06 25 4
gpt4 key购买 nike

目前我正在使用此代码:

@IBAction func selectPicture(sender: UIButton) {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.PhotoLibrary){
var imag = UIImagePickerController()
imag.delegate = self
imag.sourceType = .Camera;
imag.mediaTypes = [kUTTypeImage as String]
imag.allowsEditing = false
imag.modalPresentationStyle = .Popover
self.presentViewController(imag, animated: true, completion: nil)
}
}

但是当我在 iPhone 设备的 iPad 上运行它时,它仅询问我相机权限,并且我无法从任何设备中选择照片专辑/相机胶卷。

我该怎么做才能从设备访问照片?

最佳答案

您设置了错误的sourceType:

imag.sourceType = .Camera;

将其更改为:

imag.sourceType = .SavedPhotosAlbum;

imag.sourceType = .PhotoLibrary

常量在 UIImagePickerControllerSourceType Enumeration 中定义定义如下:

UIImagePickerControllerSourceType

The source to use when picking an image or when determining available media types. Declaration

Swift

enum UIImagePickerControllerSourceType : Int
{
case PhotoLibrary
case Camera
case SavedPhotosAlbum
}

Constants

PhotoLibrary

Specifies the device’s photo library as the source for the image picker controller.

Camera

Specifies the device’s built-in camera as the source for the image picker controller. Indicate the specific camera you want (front or rear, as available) by using the cameraDevice property.

SavedPhotosAlbum

Specifies the device’s Camera Roll album as the source for the image picker controller. If the device does not have a camera, specifies the Saved Photos album as the source.

Discussion

A given source may not be available on a given device because the source is not physically present or because it cannot currently be accessed.

关于ios - 如何使用 UIImagePickerController 从实际设备访问照片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28251033/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com