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

Rides-ios-sdk - Get cheapest product

我正在为 iOS 应用程序使用 Uber-SDK。这几天,我可以用ridesClient.fetchCheapestProduct()买到最便宜的产品。但是今天,那个函数总是 returns 一个 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)
}

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

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

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