iOS上的Uber Deeplink取件位置问题

时间:2018-10-23 15:29:03

标签: ios swift uber-api deeplink

我在我的应用程序中使用Uber和Lyft深度链接。功能是,当用户单击“乘坐优步”或“乘坐有lyft的按钮”按钮时,它将打开Uber或Lyft应用程序,并将接送和目的地坐标发送到Uber / Lyft,而Uber / Lyft应用程序将处理行程。

我为Uber使用了标准的Deeplink。当Uber已经打开并在后台运行时,一切正常。当Uber不在后台时,代答位置变成用户的当前位置(这是错误的,因为用户要指定代答位置,而不必指定当前位置)。不过,在Lyft中不会发生此问题。

这是我的代码:

class ViewController: UIViewController {

    @IBOutlet weak var uberBtn: UIButton!
    @IBOutlet weak var lyftBtn: UIButton!

    @IBAction func uberClicked(_ sender: Any) {
        if isInstalledOf(app: "uber") {
            open(scheme: "uber://?action=setPickup&client_id=7r6zjXf5e1p4nqYkX17d9R44estKs-na&product_id=a12ab23b-66f0-4028-9bb9-856dbcfdbbc7&pickup[formatted_address]=5874%20Newberry%20Street%2C%20Romulus%2C%20MI%2C%20USA&pickup[latitude]=42.265570&pickup[longitude]=-83.387391&dropoff[formatted_address]=15609%20Regina%20Avenue%2C%20Allen%20Park%2C%20MI%2C%20USA&dropoff[latitude]=42.253737&dropoff[longitude]=-83.211945")
        } else {
            open(scheme: "https://m.uber.com/ul/")
        }
    }

    @IBAction func lyftClicked(_ sender: Any) {
        if isInstalledOf(app: "lyft") {
            open(scheme: "lyft://ridetype?id=lyft&pickup[latitude]=42.265570&pickup[longitude]=-83.387391&destination[latitude]=42.253737&destination[longitude]=-83.211945")
        } else {
            open(scheme: "https://www.lyft.com/signup/SDKSIGNUP?clientId=IcEuyAmFO7Gp&sdkName=iOS_direct")
        }
    }

    // check if the app is installed
    func isInstalledOf(app: String) -> Bool {
        return UIApplication.shared.canOpenURL(URL(string: "\(app)://")!)
    }

    func open(scheme: String) {
        if let url = URL(string: scheme) {
            if #available(iOS 10, *) {
                UIApplication.shared.open(url, options: [:], completionHandler: nil)
            } else {
                UIApplication.shared.openURL(url)
            }
        }
    }
}

2 个答案:

答案 0 :(得分:1)

使用Uber SDK并传递所需的参数以进行深层链接。要解决取件地点问题,您需要传递取件名称和取件地址

        let pickupLocation          = CLLocation(latitude: <pickup latitude>, longitude: <pickup longitude>)
        let dropoffLocation         = CLLocation(latitude: <destination latitude>, longitude: <destination longitude>)
        let builder                 = RideParametersBuilder()
        builder.pickupLocation      = pickupLocation
        builder.pickupNickname      = <pickup nickname>
        builder.pickupAddress       = <pickup address>
        builder.dropoffLocation     = dropoffLocation
        builder.dropoffNickname     = <dropof nickname>
        builder.dropoffAddress      = <dropof address>
        builder.productID           = productId
        let deeplink                = RequestDeeplink(rideParameters: builder.build(), fallbackType: .appStore)
        deeplink.execute()

答案 1 :(得分:0)

我得到Uber的确认(10/29/2018),此问题是内部的。当Uber未打开且Android不存在此问题时,会发生此问题。他们正在努力解决此问题,但很遗憾,目前没有ETA。这是来自优步的消息:

  

感谢您的举报。我在Github上看到了这个问题:   https://github.com/uber/rides-ios-sdk/issues/249…我可以确认   问题。它可以在Android上正常运行,但不能在   应用未打开时的iOS。不幸的是没有ETA,但我会尽力   在内部正确路由。