UIImagePickerController falla la aplicación | Swift3, Xcode8

Para su información: Soy nuevo en Swift, así que este podría ser un problema muy simple, pero no puedo entenderlo.

He estado siguiendo el tutorial de Start Developing iOS Apps (Swift) usando Xcode 8 beta y Swift 3.

Adjunté un Receptor de gestos táctil a una vista de image y luego agregué esta acción en ViewController.swift:

@IBAction func selectImageFromPhotoLibrary(_ sender: UITapGestureRecognizer) { // Hide the keyboard. nameTextField.resignFirstResponder() // UIImagePickerController is a view controller that lets a user pick media from their photo library. let imagePickerController = UIImagePickerController() // Only allow photos to be picked, not taken. imagePickerController.sourceType = .photoLibrary // Make sure ViewController is notified when the user picks an image. imagePickerController.delegate = self present(imagePickerController, animated: true, completion: nil) } 

Cuando se selecciona la acción selectImageFromPhotLibrary Action presionando la Vista de image, la aplicación se bloquea sin mostrar el ImagePicker.

Supongo que el problema es con el nuevo presente en lugar de presentViewController que se introdujo en Swift 3


ViewController.swift

 import UIKit class ViewController: UIViewController, UITextFieldDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate { // MARK: Properties @IBOutlet weak var mealNameLabel: UILabel! @IBOutlet weak var nameTextField: UITextField! @IBOutlet weak var photoImageView: UIImageView! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically from a nib. // Handle the text field´s user input through delegate callbacks nameTextField.delegate = self } // MARK: UITextFieldDelegate func textFieldShouldReturn(_ textField: UITextField) -> Bool { // Hide the keyboard. textField.resignFirstResponder() return true } func textFieldDidEndEditing(_ textField: UITextField) { mealNameLabel.text = textField.text } // MARK: UIImagePickerControllerDelegate func imagePickerControllerDidCancel(_ picker: UIImagePickerController) { // Dismiss the picker if the user canceled. dismiss(animated: true, completion: nil) } func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) { // The info dictionary contains multiple representations of the image, and this uses the original. let selectedImage = info[UIImagePickerControllerOriginalImage] as! UIImage // Set photoImageView to display the selected image. photoImageView.image = selectedImage // Dismiss the picker. dismiss(animated: true, completion: nil) } // MARK: Actions @IBAction func selectImageFromPhotoLibrary(_ sender: UITapGestureRecognizer) { // Hide the keyboard. nameTextField.resignFirstResponder() // UIImagePickerController is a view controller that lets a user pick media from their photo library. let imagePickerController = UIImagePickerController() // Only allow photos to be picked, not taken. imagePickerController.sourceType = .photoLibrary // Make sure ViewController is notified when the user picks an image. imagePickerController.delegate = self present(imagePickerController, animated: true, completion: nil) } @IBAction func setDefaultLabelText(_ sender: UIButton) { mealNameLabel.text = "Default Text" } } 


Salida de la console

 2016-06-20 17:08:20.568093 FoodTracker[33322:696094] bundleid: com.armin.FoodTracker, enable_level: 0, persist_level: 0, propagate_with_activity: 0 2016-06-20 17:08:20.569458 FoodTracker[33322:696094] subsystem: com.apple.UIKit, category: HIDEvents, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 0 2016-06-20 17:08:20.604909 FoodTracker[33322:696090] Created DB, header sequence number = 288 2016-06-20 17:08:20.668341 FoodTracker[33322:696090] Created DB, header sequence number = 288 2016-06-20 17:08:20.743143 FoodTracker[33322:696090] subsystem: com.apple.BaseBoard, category: MachPort, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 0 2016-06-20 17:08:20.769881 FoodTracker[33322:696091] subsystem: com.apple.FrontBoard, category: Common, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 0 2016-06-20 17:08:22.007665 FoodTracker[33322:695971] subsystem: com.apple.UIKit, category: Touch, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 0 2016-06-20 17:08:22.009799 FoodTracker[33322:695971] subsystem: com.apple.UIKit, category: Gesture, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 0 2016-06-20 17:08:22.012973 FoodTracker[33322:695971] subsystem: com.apple.UIKit, category: GestureEnvironment, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 0 2016-06-20 17:08:22.013820 FoodTracker[33322:695971] subsystem: com.apple.UIKit, category: GestureExclusion, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 0 2016-06-20 17:08:23.061815 FoodTracker[33322:695971] subsystem: com.apple.photos, category: Generic, enable_level: 0, persist_level: 0, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 0, enable_oversize: 0, privacy_setting: 0 

Añade esta key a tu info.plist ,

 Key : Privacy - Photo Library Usage Description [ NSPhotoLibraryUsageDescription ] String Value : We need access to your camera roll and photo library, so that we can do operations on it. [ Customise it in your own way] 

Eso es todo, Clean & Run el proyecto.

introduzca la descripción de la imagen aquí

En xcode, se agrega la nueva key de privacidad 8 –

Medios de comunicación, location, biblioteca de fotos, recordatorios, movimiento, calendar, Bluetooth, HomeKit, camera, contactos, etc. y el valor es Descripción de la privacidad a la que accederá. "Necesitamos acceso para usar la biblioteca de fotos para que la funcionalidad funcione" o ANY_YOUR_APP_RELATED_DESCRIPTION.

introduzca la descripción de la imagen aquí

Se notó una key de camera y el valor necesario para el uso de la camera también.

Las keys requeridas tanto para la camera como para la fototeca deben estar en info.plist:

 <key>NSCameraUsageDescription</key> <string>Access needed to use your camera.</string> <key>NSPhotoLibraryUsageDescription</key> <string>Access needed to photo gallery.</string> 

Intenté agregar los posts de privacidad pero esos no funcionaron para mí. Luego miré el Inspector de Atributos para el elemento de image en sí y seleccioné el recuadro 'Interacción del usuario habilitado', que anteriormente no había sido marcado. Después de hacer esto, el selector trabajó. Espero que ayude a alguien.