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() {
tremendous.viewDidLoad()
// Do any further setup after loading the view.
let hideKeyboardGesture = UITapGestureRecognizer(goal: self, motion: #selector(hideKeyboard))
view.addGestureRecognizer(hideKeyboardGesture)
docImage.isUserInteractionEnabled = true
let docGestureRecognizer = UITapGestureRecognizer(goal: self, motion: #selector(selectDocument))
docImage.addGestureRecognizer(docGestureRecognizer)
}
@objc func hideKeyboard(){
view.endEditing(true)
}
@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)
alert.addAction(okButton)
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
}
})
}
}
}
}
}
}