【发布时间】:2019-03-27 21:51:29
【问题描述】:
我在我的应用中使用 Uber 和 Lyft 深度链接。其功能是当用户点击“乘坐优步”或“乘坐 lyft”按钮时,它将打开 Uber 或 Lyft 应用程序,并将上车和目的地坐标发送给 Uber/Lyft,由 Uber/Lyft 应用程序处理行程。
我为 Uber 使用了标准的深度链接。当 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)
}
}
}
}
【问题讨论】:
-
尝试使用用户 SDK github.com/uber/rides-ios-sdk,而不是自己实现。调试起来很容易......如果不是,而不是使用深层链接,使用通用深层链接......
-
我尝试使用 UberRides SDK 和通用深度链接,它们都无法解决这个问题 :( 一切正常,除了接送地点
-
我想这是你创建的...github.com/uber/rides-ios-sdk/issues/249...这绝对看起来像是优步应用程序的一个错误...我会说坚持下去,除非优步有人回应..
-
感谢您的链接。它不是我创建的,但我和他的问题完全相同。
-
继续关注这个问题。如果它广泛传播,肯定会有人回应它。
标签: ios swift uber-api deeplink