打开提醒,要求选择应用以打开地图 [英] Open an Alert asking to choose App to open map with

查看:77
本文介绍了打开提醒,要求选择应用以打开地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个集成了地图套件的视图控制器.我需要在打开该地图之前发出警报,要求从所有类似的地图应用程序中进行选择来打开它.例如,如果我的iPhone中安装了google maps应用,则应该有一个选项以及默认的mapkit视图.是否有可能实现此功能,该功能会扫描来自iphone的每个类似应用程序,并将结果作为打开地图的选项返回.

I have a view controller with map kit integrated. I need to shoot an alert before opening that map, asking to choose from all similar applications of maps to open it with. For instance, if google maps app is installed in my iPhone, there should be an option for it, along with the default mapkit view. Is there a possibility to achieve this functionality which scans every similar app from iphone and returns the result as options to open map with.

推荐答案

您可以使用sumesh的答案创建一系列检查以映射已安装的应用程序

You can create an array of checks to map the installed apps using sumesh's answer [1]:

var installedNavigationApps : [String] = ["Apple Maps"] // Apple Maps is always installed

以及您可以想到的每个导航应用程序:

and with every navigation app you can think of:

if (UIApplication.sharedApplication().canOpenURL(url: NSURL)) {
        self.installedNavigationApps.append(url)
} else {
        // do nothing
}

常见的导航应用是:

  • Google地图-NSURL(字符串:"comgooglemaps://")
  • Waze -NSURL(字符串:"waze://")
  • Navigon -NSURL(字符串:"navigon://")
  • TomTom -NSURL(字符串:"tomtomhome://")
  • Google Maps - NSURL(string:"comgooglemaps://")
  • Waze - NSURL(string:"waze://")
  • Navigon - NSURL(string:"navigon://")
  • TomTom - NSURL(string:"tomtomhome://")

更多信息,请访问: http://wiki.akosma.com/IPhone_URL_Schemes

创建已安装的导航应用程序列表后,可以显示一个UIAlertController:

After you created your list of installed navigation apps you can present an UIAlertController:

let alert = UIAlertController(title: "Selection", message: "Select Navigation App", preferredStyle: .ActionSheet)
for app in self.installNavigationApps {
    let button = UIAlertAction(title: app, style: .Default, handler: nil)
    alert.addAction(button)
}
self.presentViewController(alert, animated: true, completion: nil)

当然,您需要使用指定的urlscheme在处理程序中添加按钮单击的行为.例如,如果单击"Google地图",则使用类似以下的内容:

Of course you need to add the behavior of a button click in the handler with the specified urlscheme. For example if Google Maps is clicked use something like this:

UIApplication.sharedApplication().openURL(NSURL(string:
            "comgooglemaps://?saddr=&daddr=\(place.latitude),\(place.longitude)&directionsmode=driving")!) // Also from sumesh's answer

仅安装Apple Maps和Google Maps会产生类似以下内容:

With only Apple Maps and Google Maps installed this will yield something like this:

这篇关于打开提醒,要求选择应用以打开地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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