2
我已經建立並在UITableView數據中顯示圖書的應用程序。所有作品都完美無瑕,我唯一需要的是書中的照片。要上傳和檢索照片,我使用Firebase,但我不知道如何處理照片。從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 {
}
有人能寫,解釋如何做到上傳和檢索這張照片?
我假設你要上傳的照片火力地堡寄存,在這種情況下,過程記錄在這裏:HTTPS:/ /firebase.google.com/docs/storage/ios/upload-files。您還可以使用[適用於iOS的Firebase codelab](https://codelabs.developers.google.com/codelabs/firebase-ios-swift/#8),其中包含一個關於上傳圖片的步驟。 –