Swift 3中的UIImagePickerController [英] UIImagePickerController in Swift 3
问题描述
我最近使用开发者测试版更新了Xcode 8中的Swift 3。
我正在尝试实施Firebase Auth,一切进展顺利。
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.
编辑:
我正在使用GM版的xcode8,但仍然会遇到同样的错误。
I'm using the GM Version of xcode8, but still get that same error.
推荐答案
我认为您需要添加隐私 - 密钥
适用于 info.plist
文件中的camara和照片库,来自 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
此处值为字符串
不是布尔值
。
所以试试这个。
检查 Apple文档了解更多详情!
参考:这样的帖子
这篇关于Swift 3中的UIImagePickerController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!