简体   繁体   中英

Camera Roll cannot be opened in my app

Camera Roll cannot be opened in my app. In this controller, my goal is to select photos and send them to the server. PhotoController is like

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.
    }

  }

Traceback is

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

When I run my app on my real iPhone, my app stopped and this error happen. error message

I do not know why this error happen.Not codes but other setting is wrong, right?How can I fix this?

My info.plist is info.plist

I think you have not provide privacy security in your info.plist.

Privacy - Camera Usage Description -> for camera.

Privacy - Photo Library Usage Description -> for photo library.

if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.photoLibrary) {
       let imagePicker = UIImagePickerController()
       imagePicker.delegate = self
       imagePicker.sourceType = UIImagePickerControllerSourceType.photoLibrary
       self.present(imagePicker, animated: true, completion: nil)
 }

try this above code, if it does not work then check your IBAction PhotoSend Method outlet in Connection Inspector.

From the error traceback I believe the problem is with your IBAction Outlet @IBAction func PhotoSelect(_ sender: Any) . Please check the outlet for

 @IBAction func PhotoSelect(_ sender: Any) {
    }

in the interface builder and see whether you have added the outlet properly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM