显示我的“与Uber一起乘车”按钮的ETA和估计金钱选项

时间:2017-10-25 14:27:30

标签: uber-api

我已将“与Uber一起骑”按钮集成到我的应用中。我觉得,如果我显示目的地的ETA和估计价格,对用户来说会更方便。我怎么能实现这个目标?我现在正在关注本指南:https://github.com/uber/rides-ios-sdk

似乎我需要,某种产品ID 才能实现这一目标。但我怎么得到它?

enter image description here

取得了一些进展,我得到了自己的产品ID,但它仍然无效。这是我目前的代码:

enter image description here

3 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:1)

我找到了解决方案|| ViewController.swift

var button = RideRequestButton()


override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    let builder = RideParametersBuilder()
    let pickupLocation = CLLocation(latitude: 37.787654, longitude: -122.402760)
    let dropoffLocation = CLLocation(latitude: 37.775200, longitude: -122.417587)
    builder.pickupLocation  = pickupLocation
    builder.dropoffLocation = dropoffLocation
    builder.dropoffNickname = "Somewhere"
    builder.dropoffAddress  = "123 Fake St."

    var productID = ""
    let ridesClient = RidesClient()
    ridesClient.fetchProducts(pickupLocation: pickupLocation) { (product, response) in
        productID = product[1].productID!
        builder.productID = productID
    }

    ridesClient.fetchPriceEstimates(pickupLocation: pickupLocation, dropoffLocation: dropoffLocation) { (price, response) in
        print(price[0].estimate!)

        self.button.rideParameters = builder.build()
        self.button.loadRideInformation()
    }
    button.center = self.view.center
    self.view.addSubview(button)
}

此外,对UberRides-> RideRequestButton.swift `

所做的更改很少

重写public func setContent(){         super.setContent()

    uberMetadataLabel.numberOfLines = 0
    uberMetadataLabel.sizeToFit()`

private func setMultilineAttributedString(title: String, subtitle: String = "", surge: Bool = false) {
    let metadataFont = UIFont(name: "HelveticaNeue-Regular", size: 10) ?? UIFont.systemFont(ofSize: 10)

和下面的uberMetadataLabel的最后一个更改宽度(+30)一样

覆盖公共函数sizeThatFits(_ size:CGSize)-> CGSize

var width: CGFloat = 4*horizontalEdgePadding + imageLabelPadding + logoSize.width + titleSize.width+30

如有疑问,请在此处评论

答案 2 :(得分:0)

这个问题有点好笑,我认为超级应该更改那里的文档。您需要获取产品价格估算,然后 loadRideInformation()。你猜怎么了!默认按钮宽度小于要求的宽度。 (不要忘记同时添加ClientID和ServerToken)

        let pickupLocation = CLLocation(latitude:23.782221 , longitude:90.395263 )
        let dropoffLocation = CLLocation(latitude: 23.8116404, longitude: 90.4279034)

        let uberClient = RidesClient()
        let builder = RideParametersBuilder()
        let uberReqButton = RideRequestButton()
        uberReqButton.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: uberReqButton.frame.height)
        self.uberview.addSubview(uberReqButton)
        SKActivityIndicator.show()

        uberClient.fetchProducts(pickupLocation: pickupLocation, completion: { (Products, _) in
            if (Products[0].productID != nil){
                uberClient.fetchPriceEstimates(pickupLocation: pickupLocation, dropoffLocation: dropoffLocation) { (priceEstimates, Response) in

                    SKActivityIndicator.dismiss()// used for loading animation, ignore if not not needed
                    builder.pickupLocation = pickupLocation
                    builder.pickupAddress = "pickup Address"
                    builder.pickupNickname = "pickup nick"
                    builder.dropoffLocation = dropoffLocation
                    builder.dropoffAddress = "drop Address"
                    builder.dropoffNickname = "drop nick"
                    builder.productID = Products[0].productID

                    uberReqButton.rideParameters = builder.build()

                    DispatchQueue.main.async {
                        uberReqButton.loadRideInformation()
                    }
                }
            }
        })