因此,我通過imageURL將圖像發送到存儲器,但是當我嘗試將該imageURL發佈到FIRDataBase時,它會將其作爲「」或者當我設置一些條件邏輯以查看圖像是否已被選中時要做第一次登錄過程中兩次,任何人都可以幫我這個問題是在getUserNameAlert()
功能相信:如何使用Swift擊敗Firebase中的異步問題?
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
if let image = info[UIImagePickerControllerEditedImage] as? UIImage{
let imguid = NSUUID().uuidString
let metadata = FIRStorageMetadata()
metadata.contentType = "image/jpeg"
var userImagesRef = DataService.ds.REF_USER_IMAGES.child(imguid).put(UIImageJPEGRepresentation(image, 0.2)!, metadata: metadata, completion: { (metadata, error) in
if error != nil{
print("AA: able to upload image to FIREBASE STORAGE")
}else{
print("GREAT SUCCESS FOR THE STORAGE")
imageSelected = true
let downloadURL = metadata?.downloadURL()?.absoluteString
if let url = downloadURL{
userImageURL = url
}
}
})
}else{
print("AA: Valid image wasn't selected")
}
imagePicker.dismiss(animated: true, completion: nil)
}
func getUserNameAlert(user:FIRUser, provider: String){
let alert = UIAlertController(title: "Create a User Name", message: "Enter Your Desired User Name", preferredStyle: .alert)
alert.addTextField { (textField) in
textField.placeholder = "Enter User Name"
alert.addAction(UIAlertAction(title: "Create", style: .default, handler: { (action) in
if let textFields = alert.textFields{
let theTextFields = textFields as! [UITextField]
userName = theTextFields[0].text!
self.present(self.imagePicker, animated: true, completion: nil)
if imageSelected == true{
self.completeSignIn(id: user.uid, userdata: ["provider":provider,"userName":userName,"imageURL":userImageURL])
}
}
}))
self.present(alert, animated: true, completion: nil)
}
}
和userNameURL是String類型的全局變量