Waze没有从Swift加载导航

时间:2018-02-07 10:02:25

标签: ios swift swift3 openurl waze

我将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)会返回正确的网址:waze://ul?ll=48.792914,2.366290&navigate=yes,但Waze应用中没有任何内容。

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

这里有什么问题?

2 个答案:

答案 0 :(得分:6)

我解决了这个问题。 Waze documentation提供了错误的信息,因为他们的iOS示例无法按原样打开Waze应用。它在移动设备上打开Safari,然后我们需要点击链接打开Waze。

正确的链接是:

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

我需要删除网址中的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"]];
  }
}

答案 1 :(得分:0)

所选答案对我不起作用,我在安装了位智的设备上运行该应用程序,并且始终打开了该应用程序商店。使用此代码,如果已安装,它将打开位智,否则将打开appstore。

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")!)
        }
    }