Dung Nguyen
Dung Nguyen

Reputation: 3

Rides-ios-sdk - Get cheapest product

I'm using the Uber-SDK for an iOS app. Over the last few days, I can get the cheapest product with ridesClient.fetchCheapestProduct(). But today, that function always returns a nil value.

Is this a problem with the server or SDK? Please help me with this issue. (I'm in Vietnam and my client_id still works fine for Android)

This is my code:

let ridesClient = RidesClient()
let button = RideRequestButton()

override func viewDidLoad() {
    super.viewDidLoad()

    let pickupLocation = CLLocation(latitude: 37.775159, longitude: -122.417907)
    let dropoffLocation = CLLocation(latitude: 37.6213129, longitude: -122.3789554)

    //make sure that the pickupLocation and dropoffLocation is set in the Deeplink
    var builder = RideParametersBuilder()
        .setPickupLocation(pickupLocation)
        // nickname or address is required to properly display destination on the Uber App
        .setDropoffLocation(dropoffLocation, nickname: "San Francisco International Airport")

    // use the same pickupLocation to get the estimate
    ridesClient.fetchCheapestProduct(pickupLocation: pickupLocation, completion: { product, response in
        if let productID = product?.productID { //check if the productID exists
            builder = builder.setProductID(productID)
            self.button.rideParameters = builder.build()

            // show estimate in the button
            self.button.loadRideInformation()
        }
    })


    // center the button (optional)
    button.center = view.center

    //put the button in the view
    view.addSubview(button)
}

Upvotes: 0

Views: 176

Answers (1)

Charlyn G
Charlyn G

Reputation: 351

Make sure you set a server token in your Info.plist. This allows the RidesClient() to make a price estimate API call.

Copy this snippet into your Info.plist (right click and select Open As > Source Code) and replace YOUR_SERVER_TOKEN with the Server Token from your dashboard (make sure you use the server token corresponding to your client ID).

<key>UberServerToken</key>
<string>YOUR_SERVER_TOKEN</string>

Upvotes: 1

Related Questions