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

标签 ios swift uber-api

我正在为 iOS 应用程序使用 Uber-SDK。在过去的几天里,我可以使用 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)
}

最佳答案

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

将此代码段复制到您的 Info.plist(右键单击并选择 Open As > Source Code)并将 YOUR_SERVER_TOKEN 替换为仪表板中的服务器 token (确保您使用与您的客户端 ID 对应的服务器 token )。

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

关于ios - Rides-ios-sdk - 获得最便宜的产品,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44275598/

相关文章:

ios - 如何从一对多关系中正确检索 .allObjects

javascript - 尝试配置 U​​berRUSH Javascript 模块

android - 我的重定向 URL 需要哪些 SSL 证书才能安全地获取访问 token ?

iPhone - 为什么静态分析器没有选择它?

android - Facebook Unity SDK Invitable_friends API 问题

ios - 队列和 Swift 3 问题

swift - "_"和 "in"在 Swift 编程语言中是什么意思?

iOS 获取重定向的 URL

ios preferredInterfaceOrientationForPresentation 未调用

ios - 从我的应用程序获取坐标到 Uber(ios、swift4)