Swift 3 中的 UIImagePickerController [英] UIImagePickerController in Swift 3

查看:15
本文介绍了Swift 3 中的 UIImagePickerController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近使用开发人员测试版在 Xcode 8 中更新到 Swift 3.我正在尝试实施 Firebase 身份验证,一切顺利.

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.

我的问题:

我正在尝试将图片作为用户的个人资料图片上传到 Firebase 数据库.

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

我以为我可以使用 UIImagePickerController 来做到这一点,但是当我这样做时,我得到了一个

I thought I could use the UIImagePickerController to do this, but when I do, I get a

"线程 7:信号 SIGABRT

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

我失败的方法:

ViewController.swift

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

我不确定这是否只是 Swift 3 和开发人员 Xcode 8 beta 的问题,或者我是否只是为 swift 3 做错了.

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.

我正在使用 xcode8 的 GM 版本,但仍然遇到同样的错误.

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

推荐答案

我认为您需要在 info.plist 中为相机和照片库添加 privacy - key文件来自 xcode 8.例如,

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 

这里的值是 string 而不是 Boolean.

here value is string not Boolean.

所以试试这个.

检查 Apple 文档 了解更多详情!

Check Apple documentation for more details!

参考:这个帖子

这篇关于Swift 3 中的 UIImagePickerController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆