0

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()
}
AL.
  • 36,815
  • 10
  • 142
  • 281
user3708224
  • 1,229
  • 4
  • 19
  • 37
  • What line does it crash on ?? – zsteed Mar 23 '17 at 02:53
  • it gives me the error "libc++abi.dylib: terminating with uncaught exception of type NSException" in the console and then crashes in the AppDelegate file. When I let values = ["place": self.placeNameLabel.text, "name": user!.displayName] the app passes the values fine, but when I change it to let values = ["place": place.formattedAddress, "name": user!.displayName] it crashes. So the setting of place.formattedAddress is causing it to crash. – user3708224 Mar 23 '17 at 03:07
  • It seems the only difference then is `place` or `formattedAddress` might be nil. Unwrap them and make sure they are not causing the issue. – zsteed Mar 23 '17 at 20:31

0 Answers0