我正在尝试将geofire信息保存在每个postId下,但目前还不确定如何保存。有人可以帮我弄清楚如何在postId节点下保存信息。
@objc func handlePost() {
navigationItem.rightBarButtonItem?.isEnabled = false
guard let uid = Auth.auth().currentUser?.uid else { return }
guard let caption = textView.text, caption.characters.count > 0 else { return }
let userPostRef = Database.database().reference().child("posts").child(uid)
let ref = userPostRef.childByAutoId()
guard let locationName = locationNameButton.titleLabel?.text else { return }
let latitude = lat
let longitude = long
let geoLatitude = (latitude as! NSString).doubleValue
let geoLongitude = (longitude as! NSString).doubleValue
geoFireRef = Database.database().reference().child("posts").child(uid)
geoFire = GeoFire(firebaseRef: geoFireRef)
let values = ["caption": caption,"locationName": locationName, "latitude": latitude,"longitude": longitude,"creationDate": Date().timeIntervalSince1970] as [String : Any]
geoFire?.setLocation(CLLocation(latitude: geoLatitude, longitude: geoLongitude), forKey: ref.key!)
答案 0 :(得分:0)
如果要将地理位置存储在与
相同的键下 let source: ImageResource = ImageResource(downloadURL: URL(string: path)!)
let options: KingfisherOptionsInfo = [.backgroundDecode,
.processor(DefaultImageProcessor.default),
.cacheSerializer(DefaultCacheSerializer.default)]
KingfisherManager.shared.retrieveImage(with: source,
options: options,
progressBlock: nil) { (image, error, cacheType, url) in
....
}
您可以简单地从ref获取let ref = userPostRef.childByAutoId()
属性。所以:
key