Rides-ios-sdk - 获得最便宜的产品

时间:2017-05-31 04:22:19

标签: ios swift uber-api

我正在使用Uber-SDK作为iOS应用。在过去的几天里,我可以通过ridesClient.fetchCheapestProduct()获得最便宜的产品。但是今天,该函数总是返回nil值。

这是服务器或SDK的问题吗?请帮我解决这个问题。 (我在越南,我的client_id仍适用于Android)

这是我的代码:

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)
}

1 个答案:

答案 0 :(得分:1)

确保设置server token in your Info.plist。这允许RidesClient()进行价格估算API调用。

将此代码段复制到Info.plist(右键单击并选择打开方式>源代码),并将YOUR_SERVER_TOKEN替换为仪表板中的服务器令牌(确保使用与您对应的服务器令牌)客户ID)。

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