首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Waze不从Swift加载导航

Waze不从Swift加载导航
EN

Stack Overflow用户
提问于 2018-02-07 10:02:24
回答 2查看 3K关注 0票数 9

我把Waze集成到我的Swift应用程序中,但是当我点击按钮时,Waze打开了,但是导航没有什么变化。我只是看到了应用程序,仅此而已,而不是启动导航。

以下是代码:

代码语言:javascript
复制
@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文件中。)

这里怎么了?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-02-09 10:10:50

我解决了问题。Waze文件给出了错误的信息,因为他们的iOS示例没有按应有的方式打开Waze应用程序。它在移动上打开Safari,然后我们需要点击一个链接来打开Waze。

正确的链接是:

代码语言:javascript
复制
waze://?ll={latitude},{longitude}&navigate=yes

我需要删除URL中的ul

斯威夫特

代码语言:javascript
复制
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

代码语言:javascript
复制
(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"]];
  }
}
票数 14
EN

Stack Overflow用户

发布于 2020-11-28 04:53:45

选择的答案对我不起作用,我在设备上运行这个应用程序,安装了waze,它总是打开appstore。使用此代码,如果安装了waze,则打开waze;如果没有,则打开appstore。

代码语言:javascript
复制
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")!)
        }
    }
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48660902

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档