无法在我的应用程序中打开相机胶卷。 在此 Controller 中,我的目标是选择照片并将其发送到服务器。 照片 Controller 就像
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] Unknown class PhotoController in Interface Builder file. 2017-06-12 14:04:46.320479 Kenshin_Swift[265:8781] -[UIViewController PhotoSelect:]: unrecognized selector sent to instance 0x100a0c9d0 2017-06-12 14:04:46.323252 Kenshin_Swift[265:8781] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewController PhotoSelect:]: unrecognized selector sent to instance 0x100a0c9d0' * First throw call stack: (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: terminating with uncaught exception of type NSException
当我在真实的 iPhone 上运行我的应用程序时,我的应用程序停止并发生此错误。 error message
我不知道为什么会发生这个错误。不是代码而是其他设置错误,对吧?我该如何解决这个问题?
我的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)
}
尝试上面的代码,如果它不起作用,请检查连接检查器中的 IBAction PhotoSend Method 导出。
关于ios - 无法在我的应用程序中打开相机胶卷,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44491857/