【问题标题】:Waze doesn't load navigation from SwiftWaze 不从 Swift 加载导航
【发布时间】:2018-07-17 13:43:28
【问题描述】:

我将 Waze 集成到我的 Swift 应用程序中,但是当我点击按钮时,Waze 会打开,但导航没有任何反应。我只是看到应用程序,仅此而已,而不是启动导航。

代码如下:

@IBAction func openWazeAction(_ sender: Any) {
    // open waze
    if UIApplication.shared.canOpenURL(URL(string: "waze://")!) {
        let urlStr = String(format: "waze://ul?ll=%f,%f&navigate=yes", (selectedBorne?.location?.x)!, (selectedBorne?.location?.y)!)

        print(urlStr)

        UIApplication.shared.open(URL(string: urlStr)!)
    } else {
        UIApplication.shared.open(URL(string: "http://itunes.apple.com/us/app/id323229106")!)
    }
}

print(urlStr) 返回正确的 URL:waze://ul?ll=48.792914,2.366290&navigate=yes,但 Waze 应用程序中没有任何反应。

(我将 LSApplicationQueriesSchemes 放在 Info.plist 文件中。)

这里有什么问题?

【问题讨论】:

  • 它是否适用于let urlString = https://waze.com:/ul?ll=48.792914,2.366290&navigate=yes 有什么事情发生吗?来源:developers.google.com/waze/deeplinks
  • 它打开了一个 Safari 视图,我认为他们在他们的文档中犯了一个错误,因为验证 waze:// 是否存在是不合逻辑的,然后打开 https:// url。

标签: ios swift swift3 openurl waze


【解决方案1】:

所选答案对我不起作用,我在安装了位智的设备上运行该应用程序,它总是打开应用程序商店。使用此代码,如果已安装则打开 waze,如果未安装则打开应用商店。

let urlStr = String(format: "waze://?ll=%f,%f&navigate=yes", latitude, longitude)
UIApplication.shared.open(URL(string: urlStr)!) { didOpen in
        
        if !didOpen {
            UIApplication.shared.open(URL(string: "http://itunes.apple.com/us/app/id323229106")!)
        }
    }

【讨论】:

    【解决方案2】:

    我解决了这个问题。 Waze documentation 提供了错误信息,因为他们的 iOS 示例没有按应有的方式打开 Waze 应用程序。它会在移动设备上打开 Safari,然后我们需要单击一个链接来打开 Waze。

    正确的链接是:

    waze://?ll={latitude},{longitude}&navigate=yes
    

    我需要删除 URL 中的ul


    斯威夫特

    func navigateTo(latitude: Double, longitude: Double) {
        if UIApplication.shared.canOpenURL(URL(string: "waze://")!) {
            // Waze is installed. Launch Waze and start navigation
            let urlStr = String(format: "waze://?ll=%f,%f&navigate=yes", latitude, longitude)
            UIApplication.shared.open(URL(string: urlStr)!)
        } else {
            // Waze is not installed. Launch AppStore to install Waze app
            UIApplication.shared.open(URL(string: "http://itunes.apple.com/us/app/id323229106")!)
        }
    }
    

    目标-C

    (void) navigateToLatitude:(double)latitude longitude:(double)longitude
    {
      if ([[UIApplication sharedApplication]
        canOpenURL:[NSURL URLWithString:@"waze://"]]) {
          // Waze is installed. Launch Waze and start navigation
          NSString *urlStr =
            [NSString stringWithFormat:@"waze://?ll=%f,%f&navigate=yes",
            latitude, longitude];
          [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlStr]];
      } else {
        // Waze is not installed. Launch AppStore to install Waze app
        [[UIApplication sharedApplication] openURL:[NSURL
          URLWithString:@"http://itunes.apple.com/us/app/id323229106"]];
      }
    }
    

    【讨论】:

    • 这很好,但如果我想按搜索词而不是长/纬度导航怎么办?
    • 你应该对你的搜索词进行编码(比如here),然后像这样在你的URL中传递它:waze://?q=你的搜索词。
    • 试试这个"waze://?q=19+Hatzfira+st,+Jerusalem,+Israel" ,打开位智但没有导航。
    • 您应该使用 GeoCode 将您的搜索词转换为纬度和经度
    • 你可以试试这个:query = 'gas station Israel'waze://?q=query它对我有用,如果用户在设备上没有位智,你可以像这样在浏览器上打开:https://waze.com/ul?q=${query}跨度>
    猜你喜欢
    • 2018-11-18
    • 2023-03-22
    • 2018-04-29
    • 2012-08-06
    • 2019-05-12
    • 1970-01-01
    • 2019-09-19
    • 1970-01-01
    • 2018-05-09
    相关资源
    最近更新 更多