3

I have integrated a "Ride there with Uber" button to my app. I feel, it would be more convenient for the users, if i displayed the ETA and estimated pricing for the destination. How may I achieve this? I am following this guide as of now : https://github.com/uber/rides-ios-sdk

It seems like I need, some kind of product ID to be able to achieve this. But how do i get it?

enter image description here

Made some progress, I got my self the product id, but it still doesn't work. Here is my current code:

enter image description here

Sanket Ray
  • 1,071
  • 1
  • 15
  • 24

3 Answers3

1

Button will Deeplink into the Uber App and will simply open up the app. In order to see real-time fare estimates and pickup ETA information you will need to pass additional parameters to it. The Ride Request Button can accept optional parameters to pre-load some information into the ride request. You can see how to do it in the Uber documentation. Also this is explained here on the GitHub.

Sasa Jovanovic
  • 857
  • 5
  • 8
  • Could you please take a look at the question again...i edited with some changes. What am i missing? – Sanket Ray Oct 26 '17 at 13:45
  • You will need to make sure that product id you used is a valid product for the location you specified. I suggest using for testing purpose information available on uber documentation: https://developer.uber.com/docs/riders/ride-requests/tutorials/button/android#customize-button-parameters. I also suggest you to see how test's are implemented - you may find some useful information there: https://github.com/uber/rides-ios-sdk/blob/master/source/UberRidesTests/RequestButtonTests.swift. – Sasa Jovanovic Oct 27 '17 at 11:51
  • I somehow got to display the ETA. the only thing remaining is the price...After a lot of banging my head, i found out that, RidesClient.fetchRideRequestEstimate has a property called upfront fare, which may help. I am not sure, if thats the right approach? But, anyways, I always get "nil" as response from the method mentioned above :( Am I missing something?...Here's the github link : https://github.com/iamchingel/Ride-With-Uber – Sanket Ray Oct 28 '17 at 12:41
  • I have been able to get the pricing from RidesClient.fetchPriceEstimates. But I have no idea, how to integrate the price to the button :( Please help me out...I am a newbie and i have been stuck here for days now. – Sanket Ray Oct 28 '17 at 13:32
  • Sorry for late replay - what you need to do is to check do you have your : UberClientID and UberServerToken set up on the Info.plist. You can find this info on your developer dashboard. All other recomendations stay in place- so you will need to add productId, pickup and dropoff location and nickname's. – Sasa Jovanovic Dec 06 '17 at 19:44
  • Yes, I have added both the ClientID and ServerToken, but it doesn't work....As of now, my Uber button displays only ETA of the vehicle, but not the price...Would you mind taking a look at my code? Here is the github link : https://github.com/iamchingel/Ride-With-Uber – Sanket Ray Dec 08 '17 at 15:29
  • hope my answer above helps you – EarlySun Mar 25 '19 at 16:30
1

I got the solution || ViewController.swift

var button = RideRequestButton()


override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    let builder = RideParametersBuilder()
    let pickupLocation = CLLocation(latitude: 37.787654, longitude: -122.402760)
    let dropoffLocation = CLLocation(latitude: 37.775200, longitude: -122.417587)
    builder.pickupLocation  = pickupLocation
    builder.dropoffLocation = dropoffLocation
    builder.dropoffNickname = "Somewhere"
    builder.dropoffAddress  = "123 Fake St."

    var productID = ""
    let ridesClient = RidesClient()
    ridesClient.fetchProducts(pickupLocation: pickupLocation) { (product, response) in
        productID = product[1].productID!
        builder.productID = productID
    }

    ridesClient.fetchPriceEstimates(pickupLocation: pickupLocation, dropoffLocation: dropoffLocation) { (price, response) in
        print(price[0].estimate!)

        self.button.rideParameters = builder.build()
        self.button.loadRideInformation()
    }
    button.center = self.view.center
    self.view.addSubview(button)
}

Also, do make little change into UberRides->RideRequestButton.swift`

override public func setContent() { super.setContent()

    uberMetadataLabel.numberOfLines = 0
    uberMetadataLabel.sizeToFit()`

and

private func setMultilineAttributedString(title: String, subtitle: String = "", surge: Bool = false) {
    let metadataFont = UIFont(name: "HelveticaNeue-Regular", size: 10) ?? UIFont.systemFont(ofSize: 10)

and last one change width (+30) of uberMetadataLabel below like

override public func sizeThatFits(_ size: CGSize) -> CGSize

var width: CGFloat = 4*horizontalEdgePadding + imageLabelPadding + logoSize.width + titleSize.width+30

If any query please comment here

Kanhaiya Sharma
  • 1,040
  • 8
  • 20
0

The issue is kind of funny and I think uber should change there documentation. You need to fetch products and price estimates and then loadRideInformation(). Guess what! the default button width is smaller than required. (Don't forget to add both the ClientID and ServerToken)

        let pickupLocation = CLLocation(latitude:23.782221 , longitude:90.395263 )
        let dropoffLocation = CLLocation(latitude: 23.8116404, longitude: 90.4279034)

        let uberClient = RidesClient()
        let builder = RideParametersBuilder()
        let uberReqButton = RideRequestButton()
        uberReqButton.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: uberReqButton.frame.height)
        self.uberview.addSubview(uberReqButton)
        SKActivityIndicator.show()

        uberClient.fetchProducts(pickupLocation: pickupLocation, completion: { (Products, _) in
            if (Products[0].productID != nil){
                uberClient.fetchPriceEstimates(pickupLocation: pickupLocation, dropoffLocation: dropoffLocation) { (priceEstimates, Response) in

                    SKActivityIndicator.dismiss()// used for loading animation, ignore if not not needed
                    builder.pickupLocation = pickupLocation
                    builder.pickupAddress = "pickup Address"
                    builder.pickupNickname = "pickup nick"
                    builder.dropoffLocation = dropoffLocation
                    builder.dropoffAddress = "drop Address"
                    builder.dropoffNickname = "drop nick"
                    builder.productID = Products[0].productID

                    uberReqButton.rideParameters = builder.build()

                    DispatchQueue.main.async {
                        uberReqButton.loadRideInformation()
                    }
                }
            }
        })
EarlySun
  • 185
  • 2
  • 12