Ios UIImagePickerController在没有NS照片库和相机描述的情况下工作
我正在使用UIImagePickerController,因为我正在创建一个允许通过照片库和相机发布图像的应用程序。我创建了一个基本的演示,包括一个UIImageView、一个UIButton和一些设置UIImagePickerController的代码。此外,我还在Xcode的plist部分中设置了NSPhotoLibraryUsageDescription和NSCameraUsageDescription。图像拾取功能工作得很好,但当我运行模拟器时,我不会被询问是否应该让应用程序允许访问我的相机或照片库。然后我试着把plist语句取下来,然后再次运行。如果没有这些,应用程序应该崩溃,但不会崩溃。我的问题是,在没有plist的情况下,我在这里做了什么错事,为什么应用程序不请求对NS usage语句的权限Ios UIImagePickerController在没有NS照片库和相机描述的情况下工作,ios,xcode8,uiimagepickercontroller,swift4,Ios,Xcode8,Uiimagepickercontroller,Swift4,我正在使用UIImagePickerController,因为我正在创建一个允许通过照片库和相机发布图像的应用程序。我创建了一个基本的演示,包括一个UIImageView、一个UIButton和一些设置UIImagePickerController的代码。此外,我还在Xcode的plist部分中设置了NSPhotoLibraryUsageDescription和NSCameraUsageDescription。图像拾取功能工作得很好,但当我运行模拟器时,我不会被询问是否应该让应用程序允许访问我的
import UIKit
class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
@IBOutlet weak var imageView: UIImageView!
@IBAction func importImage(_ sender: UIButton) {
let imagePickerController = UIImagePickerController()
imagePickerController.delegate = self
let actionSheet = UIAlertController(title: "Add Your Profile Picture", message: "Choose An Option", preferredStyle: . actionSheet)
actionSheet.addAction(UIAlertAction(title: "Camera", style: .default, handler: { (action:UIAlertAction) in
if UIImagePickerController.isSourceTypeAvailable(.camera) {
imagePickerController.sourceType = .camera
self.present(imagePickerController, animated: true, completion: nil)
}
else {
print("Camera not Available")
}
}))
actionSheet.addAction(UIAlertAction(title: "Camera Roll", style: .default, handler:{ (action:UIAlertAction) in imagePickerController.sourceType = .photoLibrary
self.present(imagePickerController, animated: true, completion: nil)
}))
actionSheet.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil
))
self.present(actionSheet, animated: true, completion: nil)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any])
{
let image = info[UIImagePickerControllerOriginalImage] as? UIImage
imageView.image = image
picker.dismiss(animated: true, completion: nil)
}
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
picker.dismiss(animated: true, completion: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
为什么应用程序不请求NS使用声明的权限
这是由于iOS 11中的更改。通过UIImagePickerController接收UIImage不再需要用户授权
但是,如果您需要更深入的信息,即作为一个阶段集访问图像及其元数据,则需要用户授权
当然,如果你想让这个应用程序在iOS 10或之前运行,你仍然需要用户授权
为什么应用程序不请求NS使用声明的权限
这是由于iOS 11中的更改。通过UIImagePickerController接收UIImage不再需要用户授权
但是,如果您需要更深入的信息,即作为一个阶段集访问图像及其元数据,则需要用户授权
当然,如果你想让这个应用程序在iOS 10或之前运行,你仍然需要用户授权