[英]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.