【发布时间】:2019-02-08 08:17:40
【问题描述】:
在我的应用程序中,我想使用谷歌地图进行导航。所以我使用谷歌 URL 方案来实现相同的目标。导航完成后,我需要恢复我的应用程序,因此我使用了“comgooglemaps-x-callback://”选项。 我正在使用以下代码
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"comgooglemaps-x-callback://"]])
{
NSString* appName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];
NSString *string = [NSString stringWithFormat:@"comgooglemaps-x-callback://?saddr=%f,%f&daddr=%f,%f&directionsmode=driving&x-success=myapp://?resume=true&x-source=%@",sourceCoords.latitude,sourceCoords.longitude, destCoords.latitude, destCoords.longitude,appName];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:string] options:@{} completionHandler:^(BOOL success)
{
if (success)
{
NSLog(@"Opened");
ApplicationDelegate.isDirectedToGoogleMaps = YES;
}
}];
}
这里的“myapp”是我的应用程序的 URL 方案。 请检查我是否正确输入了 Google URL 方案。当我在谷歌文档中检查这个时,他们说“comgooglemaps-x-callback://”的参数与“comgooglemaps”的参数相同,需要两个额外的参数
[NSURL URLWithString:string]
上面的代码总是给出空值,并不指向谷歌地图。
仅当我使用 ("comgooglemaps-x-callback://") 回调 URL 时才会出现此问题。 当我使用没有回调选项的谷歌 URL 时,我可以启动谷歌地图。但就我而言,我想使用回调选项,以便将用户引导回源应用程序。
【问题讨论】:
标签: ios objective-c