在我的应用中,我想使用Google Maps进行导航。所以我用谷歌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”是我的应用程序的网址方案。 请检查我是否正确输入了Google URL方案。当我在google文档中对此进行检查时,他们说“ comgooglemaps-x-callback://”的参数与“ comgooglemaps”的参数相同,但需要两个附加参数
[NSURL URLWithString:string]
上面的代码始终提供空值,并且不定向到Google地图。
仅当我使用(“ comgooglemaps-x-callback://”)回调URL时,才会出现问题。 当我使用不带回叫选项的Google URL时,便可以启动Google地图。但就我而言,我想使用callback选项,以便可以将用户引导回源应用程序。
答案 0 :(得分:1)
您只能使用comgooglemaps://
打开google地图。
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"comgooglemaps://"]]) {
NSString* url = [NSString stringWithFormat: @"comgooglemaps://?daddr=%@&directionsmode=driving", encodedString];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: url] options:@{} completionHandler:^(BOOL success) {
if (success) {
//do something on success
}
}];
} else {
//if google map is not installed in device then we can open goole map in web
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://maps.google.com/maps?daddr=%@", encodedString]] options:@{} completionHandler:^(BOOL success) {
if (success) {
//do something on success
}
}];
}
不要忘记像下面这样包含在Info.plist
中。
<key>LSApplicationQueriesSchemes</key>
<array>
<string>comgooglemaps</string>
</array>
答案 1 :(得分:1)
检查以下代码以获取Swift 4.2
string scanOperator = documentData.Values["?scanOperator?"].Value;
有关权限和其他更改,您可以检查@Mahendra GP的答案。