0
爲了開發應用程序,我設置了一個帶有.savedPhotosAlbum
作爲源類型的UIImagePicker。UIImagePicker源類型不想更改
import UIKit
class PictureViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
/////////////////// OUTLETS ////////////////////
///////////////// PROPERTIES ///////////////////
var imagePicker = UIImagePickerController()
override func viewDidLoad() {
super.viewDidLoad()
imagePicker.delegate = self
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
// Where do we want our photos from and we don't want edited photos
imagePicker.allowsEditing = false
imagePicker.sourceType = UIImagePickerControllerSourceType.camera
imagePicker.cameraCaptureMode = .photo
imagePicker.modalPresentationStyle = .fullScreen
// Let's take the image from the picker
let image = info[UIImagePickerControllerOriginalImage] as! UIImage
snapImage.image = image
// When the user picks a picture, disabling the background color of the UIImageView
snapImage.backgroundColor = UIColor.clear
// Closing the image picker
imagePicker.dismiss(animated: true, completion: nil)
}
@IBAction func cameraTapped(_ sender: Any) {
present(imagePicker, animated: true, completion: nil)
}
現在,我的應用程序完成後我想嘗試一下我的iPhone我的應用程序,所以我改變了這一點:
imagePicker.sourceType = .savedPhotosAlbum
到
imagePicker.sourceType = UIImagePickerControllerSourceType.camera
而且我在info.plist
<key>NSCameraUsageDescription</key>
<string>We want to access your camera to ...</string>
但是當我嘗試拍照時,它會一直向我展示我的相冊,這就是問題所在。 我希望能夠從手機的相機拍攝照片。
你需要把更多的上下文,以便把你的代碼,你在哪裏檢查設備和呈現'picker' – Santosh
@Santosh第一次發佈關於IOS對不起,我已經添加了我的一切 – user2462805