3
var img: UIImage!
if self.profileImg.image == #imageLiteral(resourceName: "add_image"){
img = #imageLiteral(resourceName: "add_image")
}else{
img = self.profileImg.image
}
if let imgData = UIImageJPEGRepresentation(img, 0.2){
print(imgData)
let imageUid = NSUUID().uuidString
print(imageUid)
let metaData = StorageMetadata()
print(metaData)
metaData.contentType = "image/jpeg"
DataService.ds.REF_PROFILE_IMAGES.child(imageUid).putData(imgData, metadata: metaData, completion: { (metadata, error) in
if error != nil {
print ("ADAM: UNABLE TO UPLOAD IMAGE TO FIREBASE STORAGE")
}else{
print ("ADAM: SUCCESSFULLY UPLOADED PROFILE IMAGE ")
self.downloadURL = metaData.downloadURL()?.absoluteString
}
})
}else{
print("ADAM: SUMTING WONG")
}
Auth.auth().createUser(withEmail: emailField.text!, password: passwordField.text!) { (user, error) in
if error == nil {
print("ADAM: You have successfully signed up")
// saving the image to storage and link to database
let firstName = self.firstNameField.text
let lastName = self.LastNameField.text
let userName = self.usernameField.text
let profileImageUrl = self.downloadURL
print(profileImageUrl)
let userData = ["provider" : user!.providerID, "FirstName": firstName, "LastName": lastName, "username": userName, "profileImageURL": profileImageUrl]
self.completeSignIn(id: user!.uid, userData: userData as! Dictionary<String, String>)
配置文件圖像URL重複返回零,因此不會允許我運行登錄功能。當我調試時,我可以看到Dataservice方法被跳過,我不明白爲什麼:/嘗試將圖片上傳到Firebase存儲但未執行?
你看到爲零,因爲'putData'是一個異步調用,所以你需要可以調用'createUser'方法裏面'putData'關閉或使用完成處理程序,你可以檢查此:https://stackoverflow.com/questions/46356012/firebase-one-of-two-observers-not-working/46356267#46356267 – 3stud1ant3
@ 3stud1ant3我試過在putData完成處理程序中創建用戶,但仍然沒有運氣 – KONADO