so I am trying to pass GMSPlace data from GooglePlaces to a UIView, and then from the UIView into Firebase. I am able to pass it into a String into the UIView ("text text...(value)...text text"), but then I want to pass just the value again to Firebase after the user presses a confirm button (so not the entire string of text from the UIView. My app crashes when I tap the Confirm button. Thanks for any and all help!
// 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()
}