Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 954
Dowland Aiello Avatar asked Sep 10 '16 17:09

Dowland Aiello


2 Answers

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 

here value is string not Boolean.

so try this.

Check Apple documentation for more details!

Reference : this so post

like image 121
Ketan Parmar Avatar answered Oct 25 '22 08:10

Ketan Parmar


Follow the error message from xCode, and add key/value to Info.plist of application.

For example, I got an error message from my developing app. It reminds me to add NSCameraUsageDescription to app's Info.plist.


The error message from xCode

This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSCameraUsageDescription key with a string value explaining to the user how the app uses this data.


And MORE

Add key/value pair to Localizable.strings, it will give i18n support. For example, I add a pair to Localizable.strings (English). It will give English description when ask user about camera permission.

"NSCameraUsageDescription" = "We needs camera permission to capture image.";
like image 23
AechoLiu Avatar answered Oct 25 '22 10:10

AechoLiu