优步iOS SDK - 如何实现自定义Uber Ride请求按钮

时间:2016-09-06 07:14:59

标签: ios swift uber-api

我正在使用Uber SDK for iOS。如何在Swift中实现自定义Uber Rides Request按钮?我不想使用优步在其文档中使用的标准按钮。我想为它设计自己的UI。 Reference

2 个答案:

答案 0 :(得分:3)

您可以使用以下内容在swift中创建一个乘车请求按钮:

let button = RideRequestButton()
let ridesClient = RidesClient()
let pickupLocation = CLLocation(latitude: 37.787654, longitude: -122.402760)
let dropoffLocation = CLLocation(latitude: 37.775200, longitude: -122.417587)
let builder = RideParametersBuilder().setPickupLocation(pickupLocation).setDropoffLocation(dropoffLocation, nickname: "Somewhere", address: "123 Fake St.")
ridesClient.fetchCheapestProduct(pickupLocation: pickupLocation, completion: {
    product, response in
    if let productID = product?.productID {
        builder = builder.setProductID(productID)
        button.rideParameters = builder.build()
        button.loadRideInformation()
}
})

您想要自定义(产品,提货,下车)?根据您要自定义的内容,您可以在此处查看文档中的示例:https://developer.uber.com/docs/rides/ride-request-buttons

答案 1 :(得分:2)

如果您只想要深层链接功能,可以使用RequestDeeplink类。类似的东西:

func setup() {
    let rideParameters = RideParametersBuilder().build()
    let deeplink = RequestDeeplink(rideParameters: rideParameters)
    let button = UIButton()
    button.addTarget(self, action: #selector(buttonAction), forControlEvents: .TouchUpInside)
}

func buttonAction() {
     deeplink.execute()
}