ios – Waze不加载Swift的导航

我将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文件中.)

这有什么不对?

解决方法

解决了这个问题. 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,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,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"]];
  }
}

相关文章

UITabBarController 是 iOS 中用于管理和显示选项卡界面的一...
UITableView的重用机制避免了频繁创建和销毁单元格的开销,使...
Objective-C中,类的实例变量(instance variables)和属性(...
从内存管理的角度来看,block可以作为方法的传入参数是因为b...
WKWebView 是 iOS 开发中用于显示网页内容的组件,它是在 iO...
OC中常用的多线程编程技术: 1. NSThread NSThread是Objecti...