gpt4 book ai didi

iphone - 无法从另一个应用程序内启动 Google map 应用程序

转载 作者:行者123 更新时间:2023-11-29 04:04:22 25 4
gpt4 key购买 nike

我正在尝试从 iOS 应用程序内部打开 Google map 应用程序。

我正在使用此代码:

[[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"comgooglemaps://?center=40.765819,-73.975866&zoom=14&views=traffic"]];

但它不起作用。谁能告诉我这是什么问题?

最佳答案

首先,canOpenURL 不会打开应用程序。它只是检查应用程序是否可以打开应用程序。请改用 openURL 方法。

if([[UIApplication sharedApplication] canOpenURL: [NSURL URLWithString:@"comgooglemaps://?center=40.765819,-73.975866&zoom=14&views=traffic"]])
{
[[UIApplication sharedApplication] openURL: [NSURL URLWithString:@"comgooglemaps://?center=40.765819,-73.975866&zoom=14&views=traffic"]];
}

注意:

用于使用 URL 方案打开第三方应用程序。它应该安装在设备上。

canOpenURL:

Returns whether an application can open a given URL resource.

- (BOOL)canOpenURL:(NSURL *)url

Parameters

url

A URL object that identifies a given resource. The URL’s scheme—possibly a custom scheme—identifies which application can

handle the URL.

Return Value

NO if no application is available that will accept the URL; otherwise, returns YES.

Discussion

This method guarantees that that if openURL: is called, another application will be launched to handle it. It does not guarantee that the full URL is valid.


openURL:

Opens the resource at the specified URL.

- (BOOL)openURL:(NSURL *)url

Parameters

url

An object representing a URL (Universal Resource Locator). UIKit supports the http:, https:, tel:, and mailto: schemes.

Return Value

YES if the resource located by the URL was successfully opened; otherwise NO.

Discussion

The URL can locate a resource in the same or other application. If the resource is another application, invoking this method may cause the calling application to quit so the other one can be launched.

You may call canOpenURL: before calling this one to verify that there is an application that can handle it.

请引用UIApplication Class .

关于iphone - 无法从另一个应用程序内启动 Google map 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15470169/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com