位智不会从Swift加载导航 [英] Waze doesn't load navigation from Swift

查看:95
本文介绍了位智不会从Swift加载导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I integrated Waze into my Swift app, but when I click on the button, Waze opens but nothing happens with the navigation. I juste see the app and that's all, instead of launching the navigation.

这是代码:

@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,但是位智应用程序中没有任何反应.

The print(urlStr) returns the right URL: waze://ul?ll=48.792914,2.366290&navigate=yes, but nothing happens in the Waze app.

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

这是怎么了?

推荐答案

我已解决此问题. Waze文档提供了错误的信息,因为他们的iOS示例无法打开Waze应用程序,因为它应该是.它会在移动设备上打开Safari,然后我们需要单击链接以打开Waze.

I fixed the problem. The Waze documentation gives wrong information because their iOS example doesn't open the Waze app as it should be. It opens Safari on mobile and then we need to click on a link to open Waze.

正确的链接是:

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

我需要删除URL中的ul.

I needed to remove ul in the URL.

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


Objective-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"]];
  }
}

这篇关于位智不会从Swift加载导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆