所以我试图将GMPlace数据从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()
}