gpt4 book ai didi

ios - 关于构建应用程序的建议

转载 作者:行者123 更新时间:2023-11-30 11:44:54 24 4
gpt4 key购买 nike

我不确定我的应用程序结构是否正确。我是第一次使用结构,我正在尝试保存用户的位置并使用 Firebase 创建用户。我想仅按位置显示所有用户。 Global.refString 是从 UIPicker 中设置的,该 UIPicker 是用 6 个不同位置硬编码的。 loadUserInfo() 未返回任何信息。我第一次尝试时它有效,但重新打开并关闭应用程序后它总是返回空。我不确定每次打开应用程序时是否都会保存结构。我应该使用不同的方法来完成这些任务吗?

private func saveUserInfo(firstLastName: String, user: User!, location: String, biography: String, password: String, phoneNumber: String){
let locationRef = Global.refString
let userInfo = ["firstLastName": firstLastName, "email": user.email!, "password": password, "location": location, "phoneNumber": phoneNumber, "biography": biography, "uid": user.uid, "photoURL": String(describing: user.photoURL!)] as [String : Any]

let userRef = dataBaseRef.child(locationRef!).child(user.uid)
userRef.setValue(userInfo) { (error, ref) in
if error == nil{
print("USER SAVED")
self.logIn(email: user.email!, password: password)
}else{
print(error?.localizedDescription)

}
}
}



func loadUserInfo(){

let locationRef = Global.refString
let userRef = dataBaseRef.child(locationRef!).child(Auth.auth().currentUser!.uid)

userRef.observe(.value, with: { (snapshot) in

let user = Users(snapshot: snapshot)

if let username = user.name{
self.nameLabel.text = username
}

if let number = user.phoneNumber{
self.phone = Int(number)
}
if let userLocation = user.location{
self.bioLabel.text = userLocation
}
self.storageRef.storage.reference(forURL: imageOld).getData(maxSize: 10 * 1024 * 1024, completion: { (imgData, error) in

if error == nil {
DispatchQueue.main.async {
if let data = imgData {
self.avatar.image = UIImage(data: data)
}
}
}else {
print(error!.localizedDescription)

}
}
)}
}) { (error) in
print(error.localizedDescription)
}
}
}



struct Global
{
static var Location : String!
static var usersListSent
= [String]()
static var refString: String!
}

最佳答案

尝试:

Database.database().reference().child(Global.refString).child(id).observeSingleEvent(of: .value) { (snapshot) in 
if let snapshots = snapshot.children.allObjects as? [DataSnapshot] {
for snap in snapshots {
print(snap)
}
}

关于ios - 关于构建应用程序的建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48961790/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com