【发布时间】:2017-05-09 21:08:40
【问题描述】:
我已经构建了一个应用程序,它显示在书籍的 UITableView 数据中。一切都很完美,我唯一需要的是这本书的照片。要上传和检索照片,我使用 Firebase,但我不知道如何处理照片。
这是我已经实现的:
@IBAction func ButtonScatta(_ sender: UIButton) {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.camera;
imagePicker.allowsEditing = false
self.present(imagePicker, animated: true, completion: nil)
}
}
@IBAction func ButtonScegli(_ sender: UIButton) {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.photoLibrary) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.photoLibrary;
imagePicker.allowsEditing = true
self.present(imagePicker, animated: true, completion: nil)
}
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [AnyHashable: Any]!) {
ImageView.image = image
self.dismiss(animated: true, completion: nil);
}
这就是“Vendi”按钮的功能:
if let user = FIRAuth.auth()?.currentUser{
self.emailUser.text = user.email
let userID: String = user.uid
let x = libriArray.count
let y = String(x+1)
//let imageLibro: UIImage = self.ImageView.image!
let emailVenditore: String = self.emailUser.text!
let titoloLibro: String = self.TitoloText.text!
let codiceLibro: String = self.ISBNText.text!
let prezzoLibro: String = self.PrezzoText.text!
let edizioneLibro: String = self.EdizioneText.text!
let statoLibro: Bool = false
let Libro = ["titolo": titoloLibro, "codice": codiceLibro, "prezzo": prezzoLibro, "autore": edizioneLibro, "emailUser": emailVenditore, "userID": userID, "stato": statoLibro] as [String : Any]
let libriRef = ref.child(byAppendingPath: "Libri")
var libri = [y: Libro]
libriRef.childByAutoId().setValue(Libro)
self.dismiss(animated: true, completion: nil)
} else {
}
有人可以写并解释如何上传和检索这些照片吗?
【问题讨论】:
-
我假设您要将照片上传到 Firebase 存储,在这种情况下,该过程记录在此处:firebase.google.com/docs/storage/ios/upload-files。也可以拨打Firebase codelab for iOS,里面有上传图片的步骤。
标签: ios swift uitableview firebase photo