所以我试图将 GMSPlace 数据从 GooglePlaces 传递到 UIView,然后从 UIView 传递到 Firebase。我可以将它传递给 UIView 中的字符串(“文本文本...(值)...文本文本”),但是我想在用户按下确认按钮后再次将值传递给 Firebase(所以不是来自 UIView 的整个文本字符串。当我点击“确认”按钮时,我的应用程序崩溃了。感谢所有帮助!
// MARK: GOOGLE AUTO COMPLETE DELEGATE
func viewController(_ viewController: GMSAutocompleteViewController, didAutocompleteWith place: GMSPlace) {
let placeID = place.placeID
placesClient.lookUpPlaceID(placeID, callback: { (place, error) -> Void in
if let error = error {
print("lookup place id query error: \(error.localizedDescription)")
return
}
guard let place = place else {
print("No place details for \(placeID)")
return
}
print("Place name \(place.name)")
print("Place address \(place.formattedAddress)")
print("Place placeID \(place.placeID)")
print("Place attributions \(place.attributions)")
})
let selectedPlace = place.formattedAddress
if let name = selectedPlace as String!
{
self.placeNameLabel.text = "Are you sure you would like to add \(name) to your places?"
}
self.dismiss(animated: true, completion: nil)
setupConfirmationPopUp()
}
// user taps button to send item to be updated in Firebase data tree
func confirmAddPlace(place: GMSPlace) {
// add place to tableview array
let accessToken = FBSDKAccessToken.current()
guard let accessTokenString = accessToken?.tokenString else { return }
let credentials = FIRFacebookAuthProvider.credential(withAccessToken: accessTokenString)
FIRAuth.auth()?.signIn(with: credentials, completion: { (user, error) in
if error != nil {
print("Something went wrong with our FB user: ", error ?? "")
return
}
// create place on tap pf confirm
let ref = FIRDatabase.database().reference().child("places")
let childRef = ref.childByAutoId()
let values = ["place": place.formattedAddress, "name": user!.displayName]
childRef.updateChildValues(values)
})
animateOut()
}