C# 如何检查iPhone在Xamarin.Forms中设置了谷歌地图应用程序的设备?

C# 如何检查iPhone在Xamarin.Forms中设置了谷歌地图应用程序的设备?,c#,.net,xamarin,xamarin.forms,C#,.net,Xamarin,Xamarin.forms,我有一个问题是使用谷歌地图打开地图: 我的设备iPhone设置了谷歌地图应用程序,但按下按钮时我的应用程序链接到地图应用程序以打开地图。设备打开Safari,不打开谷歌地图 我试着这样做: 但在代码行: var canOpenNative = UIApplication.SharedApplication.CanOpenUrl(NSUrl.FromString("comgooglemaps-x-callback://")); 我不能使用图书馆:`使用基金会 (生成应用程序将无法使用库。) 我试

我有一个问题是使用谷歌地图打开地图:

我的设备iPhone设置了谷歌地图应用程序,但按下按钮时我的应用程序链接到地图应用程序以打开地图。设备打开Safari,不打开谷歌地图

我试着这样做:

但在代码行:

var canOpenNative = UIApplication.SharedApplication.CanOpenUrl(NSUrl.FromString("comgooglemaps-x-callback://"));
我不能使用图书馆:`使用基金会

(生成应用程序将无法使用库。)

我试着这样做:

但在构建应用程序时,我无法使用libraryFoundation构建

那么,还有其他方法吗,如何检查iPhone在Xamarin.Forms中设置应用程序Google Maps的设备


谢谢 您可以使用依赖项服务从共享代码调用特定于平台的代码。按照以下步骤创建依赖项服务,以检查IPhone是否安装了Google Maps:

步骤1:在共享代码中创建一个接口

public interface IMapService
{
     bool HasGoogleMapAvailable();
}
第2步:现在在您的平台特定项目中;现在这是你的iOS项目。创建将实现您创建的接口的服务:

[assembly: Dependency(typeof(MapService))]
namespace WorkingWithMaps.iOS
{
    public class MapService:IMapService
    {
        public MapService()
        {
        }

        public bool HasGoogleMapAvailable()
        {
            var result=UIApplication.SharedApplication.CanOpenUrl(NSUrl.FromString("comgooglemaps-x-callback://"));
            return result;
        }
    }
}
步骤3:在共享代码中,您可以使用该依赖项服务:

IMapService mapService = DependencyService.Get<IMapService>();
var isInstalled = mapService.HasGoogleMapAvailable();

Console.WriteLine("Google Map is installed :" + isInstalled);

您可以通过表单依赖项服务调用本机代码:是否已将Google Maps设置为安装在设备上或设置为默认映射应用程序?@Adriani6 I want check on device(iPhone)已设置Google Maps。若设备并没有应用程序谷歌地图,设备将打开地图到Safari或其他应用程序地图。
var uri = new Uri("http://maps.google.com/maps?saddr=Google+Inc,+8th+Avenue,+New+York,+NY&daddr=John+F.+Kennedy+International+Airport,+Van+Wyck+Expressway,+Jamaica,+New+York&directionsmode=transit");
Device.OpenUri(uri);