[英]Camera Roll cannot be opened in my app
无法在我的应用中打开“相机胶卷”。 在此控制器中,我的目标是选择照片并将其发送到服务器。 PhotoController就像
import Foundation
import UIKit
class PhotoController:UIViewController,UINavigationControllerDelegate,UIImagePickerControllerDelegate{
@IBOutlet weak var myImageView: UIImageView!
@IBAction func PhotoSelect(_ sender: Any) {
}
@IBAction func PhotoSend(_ sender: Any) {
let myPickerController = UIImagePickerController()
myPickerController.delegate = self;
myPickerController.sourceType = UIImagePickerControllerSourceType.photoLibrary
self.present(myPickerController, animated: true, completion: nil)
}
private func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject])
{
myImageView.image = info[UIImagePickerControllerOriginalImage] as? UIImage
self.dismiss(animated: true, completion: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//myImageUploadRequest()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
追溯是
2017-06-12 14:04:43.054105 Kenshin_Swift [265:8781] Interface Builder文件中的未知类PhotoController。 2017-06-12 14:04:46.320479 Kenshin_Swift [265:8781]-[UIViewController PhotoSelect:]:无法识别的选择器已发送到实例0x100a0c9d0 2017-06-12 14:04:46.323252 Kenshin_Swift [265:8781] *由于以下原因终止了应用程序未捕获的异常'NSInvalidArgumentException',原因是: ' - [UIViewController中PhotoSelect:]:无法识别的选择发送到实例0x100a0c9d0' *第一掷调用堆栈:(0x184a211b8 0x18345855c 0x184a28268 0x184a25270 0x18491e80c 0x18a90bd30 0x18a90bcb0 0x18a8f6128 0x18a90b59c 0x18a90b0c4 0x18a906328 0x18a8d6da0 0x18b0c075c 0x18b0ba130 0x1849ceb5c 0x1849ce4a4 0x1849cc0a4 0x1848fa2b8 0x1863ae198 0x18a9417fc 0x18a93c534 0x1000f5274 0x1838dd5b8)libc ++ abi.dylib:以类型为NSException的未捕获异常终止
当我在真实的iPhone上运行我的应用程序时,我的应用程序停止了,并发生了此错误。 错误信息
我不知道为什么会发生此错误。不是代码,而是其他设置错误,对吗?我该如何解决?
我的info.plist是info.plist
我认为您尚未在info.plist中提供隐私保护。
隐私-相机使用说明->相机。
隐私-图片库使用说明->图片库。
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.photoLibrary) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.photoLibrary
self.present(imagePicker, animated: true, completion: nil)
}
请尝试上面的代码,如果它不起作用,请在Connection Inspector中检查IBAction PhotoSend Method出口。
从错误回溯中,我相信问题出在您的IBAction Outlet @IBAction func PhotoSelect(_ sender: Any)
。 请检查插座
@IBAction func PhotoSelect(_ sender: Any) {
}
在界面构建器中,查看是否已正确添加插座。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.