DA Labs DA Labs - 2 months ago 230
iOS Question

UIImagePickerController in Swift 3

I've recently updated to Swift 3 in Xcode 8 using the developer beta.
I'm trying to implement Firebase Auth, and everything's going well.

My Problem:

I'm trying to upload an image as a user's profile picture to a Firebase database.

I thought I could use the

UIImagePickerController
to do this, but when I do, I get a


"Thread 7: Signal SIGABRT


I know what this would normally indicate, but I checked, and my image does indeed print my test statement when I tap it.

My failed method:

ViewController.swift

import UIKit
import Firebase
import Photos

class ViewController: UIViewController, UITextFieldDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate{

@IBOutlet weak var imageView: UIImageView!
@IBOutlet var emailTextField: UITextField!
@IBOutlet var passWordTextField: UITextField!
@IBOutlet var nameTextField: UITextField!

override func viewDidLoad() {
super.viewDidLoad()

if FIRAuth.auth()?.currentUser?.uid != nil {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let view = storyboard.instantiateViewController(withIdentifier: "ProfileViewController")
self.present(view, animated: true, completion: nil)
}

imageView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(handleSelectProfileImageView)))
imageView.isUserInteractionEnabled = true

self.emailTextField.delegate = self;
self.passWordTextField.delegate = self;
self.nameTextField.delegate = self;
}

func handleSelectProfileImageView() {
let picker = UIImagePickerController()

picker.delegate = self
picker.allowsEditing = true

present(picker, animated: true, completion: nil)
}


I'm not sure yet if this is just a problem with Swift 3 and the developer Xcode 8 beta, or if I'm just doing it the wrong way for swift 3.

EDIT:

I'm using the GM Version of xcode8, but still get that same error.

Screenshot

screenshot2

screenshot3

Answer

I think you need to add privacy - key for camara and photo library in your info.plist file as from xcode 8. for example,

 Key : Privacy - Media Library Usage Description
 Value : YES 

 Key : Privacy - Photo Library Usage Description
 Value : YES 

 Key : Privacy - Camara Usage Description
 Value : YES 

so try this.

Check Apple documentation for more details!

Reference : this so post