优步按钮不显示价格,但仅限时间

时间:2017-12-17 12:17:57

标签: ios uber-api

这是我第一次使用Uber api。我清楚地遵循了说明,但它从未真正提到如何在按钮中显示价格估算。我的代码神奇地显示时间(不知道为什么或如何)。请解释如何显示价格。服务器令牌和客户端ID都已集成在info.plist文件中。

class ViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()

    let button = RideRequestButton()
    view.addSubview(button)
    button.center = view.center
    let ridesClient = RidesClient()
    let dropOffLocation = CLLocation(latitude: 20.301647, longitude: 85.819135)
    let pickUpLocation = CLLocation(latitude : 20.323706, longitude: 85.814981)
    let builder = RideParametersBuilder()
    builder.pickupLocation = pickUpLocation
    builder.pickupNickname = "Home"
    builder.dropoffLocation = dropOffLocation
    builder.dropoffNickname = "Mayfair Lagoon, Bhubaneswar"

    var productID = ""
    ridesClient.fetchProducts(pickupLocation: pickUpLocation) { (product, response) in
        productID = product[1].productID
        print("\(productID)")
    }


    ridesClient.fetchPriceEstimates(pickupLocation: pickUpLocation, dropoffLocation: dropOffLocation) { (price, response) in

        print(price[0].estimate!,"")
    }

    ridesClient.fetchTimeEstimates(pickupLocation: pickUpLocation) { (time, response) in
        print("",time[0].estimate,"")
    }


    builder.productID = productID

    button.setContent()
    button.rideParameters = builder.build()
    button.loadRideInformation()

}

}

2 个答案:

答案 0 :(得分:1)

按钮将深入链接到优步应用程序,只需打开应用程序即可。为了查看实时票价估算和提取ETA信息,您需要将附加参数传递给它。乘坐请求按钮可以接受可选参数以将一些信息预加载到乘坐请求中。您可以在Uber documentation中查看如何执行此操作。这也是在GitHub上解释here

请查看StackOverflow线程here。 解释并记录了如何管理此问题。

答案 1 :(得分:0)