因此,我通过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类型的全局变量