我在应用程序中实现了以下代码,以允许用户向应用程序添加图像。但是,永远不会要求用户授予访问照片的权限。我在这里想念什么?
在我的info.plist中,我设置了:隐私-图片库使用说明=请提供对您图片库的访问权限
捆绑包标识符为:$(PRODUCT_BUNDLE_IDENTIFIER)
import UIKit
class NewPostXIB: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
@IBOutlet weak var image: UIImageView!
let imagePicker = UIImagePickerController()
override func viewDidLoad() {
super.viewDidLoad()
imagePicker.delegate = self
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
super.touchesBegan(touches, with: event)
self.view.endEditing(true)
}
@IBAction func closeButton(_ sender: Any) {
dismiss(animated: false, completion: nil)
}
@IBAction func addImageButton(_ sender: Any) {
if UIImagePickerController.isSourceTypeAvailable(.photoLibrary) {
imagePicker.allowsEditing = true
imagePicker.sourceType = .photoLibrary
present(imagePicker, animated: true, completion: nil)
}
}
func imagePickerController(_ picker: UIImagePickerController, …Run Code Online (Sandbox Code Playgroud) 这是我的代码,可让用户选择个人资料照片:
早些时候,我只允许用户用相机拍照作为个人资料图片,但我决定更改它,以便用户现在可以从照片库中选择照片。
问题是我的用户能够访问照片库,而不会收到访问其照片库的请求警报。“某某应用程序想要访问您的照片库”。我有 Info.plist 用于照片库使用和照片库添加使用。此外,当我的应用程序在模拟器中运行时,当我进入“设置”然后进入“隐私”时,我会转到“照片”以查看我的应用程序是否具有访问权限,但那里没有任何内容提到我的应用程序可以访问照片库。
如果有人可以帮助我弄清楚我做错了什么以及如何让访问“照片库”的请求正常工作,我将不胜感激!谢谢。
class ProfileImageVC: UIViewController {
@IBOutlet weak var AddAProfilePictureLabel: UILabel!
@IBOutlet weak var ProfilePictureImageView: UIImageView!
@IBOutlet weak var TapToChangeButton: UIButton!
@IBOutlet var ErrorLabel: UILabel!
@IBOutlet var FinishButton: UIButton!
var ImagePicker:UIImagePickerController!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let imageTap = UITapGestureRecognizer(target: self, action: #selector(openImagePicker))
ProfilePictureImageView.isUserInteractionEnabled = true
ProfilePictureImageView.addGestureRecognizer(imageTap)
ProfilePictureImageView.layer.cornerRadius = ProfilePictureImageView.bounds.height / 2
ProfilePictureImageView.clipsToBounds = true
TapToChangeButton.addTarget(self, action: #selector(openImagePicker), for: .touchUpInside)
//when user clicks they can choose a …Run Code Online (Sandbox Code Playgroud)