Tuesday, September 26, 2023
HomeiOS Developmentios - i can not add information to firebase with Swift

ios – i can not add information to firebase with Swift

I’ve uploaded the images on the consumer’s cellphone to firebase with UIImagePickerController, however utilizing UIdocumentPickerController, I load pdf and comparable codecs, but it surely masses an empty file and when I attempt to obtain the information I’ve uploaded, it downloads an empty file- I’m new to Swift, can anybody assist?

import UIKit
import Firebase
import MobileCoreServices
class DocViewController: UIViewController & UIDocumentPickerDelegate & UINavigationControllerDelegate{
@IBOutlet weak var docImage: UIImageView!

override func viewDidLoad() {
    // Do any further setup after loading the view.
    let hideKeyboardGesture = UITapGestureRecognizer(goal: self, motion: #selector(hideKeyboard))
    docImage.isUserInteractionEnabled = true
    let docGestureRecognizer = UITapGestureRecognizer(goal: self, motion: #selector(selectDocument))
@objc func hideKeyboard(){
@objc func selectDocument(){
    let documentPicker = UIDocumentPickerViewController(documentTypes: [String(kUTTypePDF)], in: .open)
    documentPicker.delegate = self
    documentPicker.modalPresentationStyle = .fullScreen
    documentPicker.allowsMultipleSelection = false
    documentPicker.directoryURL = .documentsDirectory
    current(documentPicker, animated: true, completion: nil)
func alertFunc(titleInput:String, messageInput: String){
    let alert = UIAlertController(title: titleInput, message: messageInput, preferredStyle: UIAlertController.Fashion.alert)
    let okButton = UIAlertAction(title: "OK", fashion: UIAlertAction.Fashion.default, handler: nil)
    self.current(alert, animated: true, completion: nil)

@IBAction func uploadClicked(_ sender: Any) {
    let storage = Storage.storage()
    let storageReference = storage.reference()
    let newData = Knowledge()
    let newUuid = UUID().uuidString
    let mediaFolder = storageReference.baby("Paperwork")
    let newDocumentReference = mediaFolder.baby("(newUuid).pdf")
    newDocumentReference.putData(newData, metadata: nil) { metadata, error in
     if error != nil {
     self.alertFunc(titleInput: "Error", messageInput: error?.localizedDescription ?? "Error!!!")
     } else{
     newDocumentReference.downloadURL { url, error in
     if error == nil{
     let documentUrl = url?.absoluteString
     let documentFirestore = Firestore.firestore()
     var documentFirestoreReference : DocumentReference? = nil
     let firestorePost = ["imageUrl": documentUrl!, "PostedBy": Auth.auth().currentUser!.email!, "Date": FieldValue.serverTimestamp()] as [String : Any]
     documentFirestoreReference = documentFirestore.assortment("Paperwork").addDocument(knowledge: firestorePost, completion: { error in
     if error != nil {
     self.alertFunc(titleInput: "Error!!!", messageInput: error?.localizedDescription ?? "Error!!!")
     } else {
     self.tabBarController?.selectedIndex = 0




Please enter your comment!
Please enter your name here

Most Popular

Recent Comments