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

问题描述 投票:2回答:3

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

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

enter image description here

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

enter image description here

uber-api
3个回答
1
投票

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


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`做一点改动

override 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)一样

覆盖public func sizeThatFits(_ size:CGSize) - > CGSize

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

如有任何疑问请在这里评论


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()
                    }
                }
            }
        })
© www.soinside.com 2019 - 2024. All rights reserved.