从浏览器打开 iOS 应用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25883113/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Open iOS app from browser
提问by Sagar
What I want to do is, We have having one product info on Website. That product is available on store. what we have on website is that, Product info and one button for that product.
我想要做的是,我们在网站上有一个产品信息。该产品可在商店购买。我们在网站上拥有的是,产品信息和该产品的一个按钮。
I want to take two actions on that button. When User opens website on iPad or iPhone on Safari (browser) and click on GetProduct button, then following two actions must be taken place. 1. If user is already having product installed on device then directly open the app in device. 2. If user is not having the app on device then link user to the app on store, so he can download from there.
我想对该按钮执行两个操作。当用户在 iPad 或 iPhone 上的 Safari(浏览器)上打开网站并单击 GetProduct 按钮时,必须执行以下两个操作。1. 如果用户已经在设备上安装了产品,则直接在设备中打开应用程序。2. 如果用户没有在设备上安装该应用程序,则将用户链接到商店中的应用程序,以便他可以从那里下载。
I already handled second condition, but how to handle the first condition. If I am already having the app then how to open it on action of button click in browser.
我已经处理了第二个条件,但是如何处理第一个条件。如果我已经拥有该应用程序,那么如何在浏览器中单击按钮时打开它。
回答by Gad
You can achieve what you're asking for by using a URL scheme. This will enable you to call the openUrl:
method with your application's url scheme which will then launch your app.
Here's how you setup a custom url scheme:
您可以通过使用URL 方案来实现您的要求。这将使您能够openUrl:
使用应用程序的 url 方案调用该方法,然后将启动您的应用程序。以下是设置自定义 url 方案的方法:
- Open your app's Info.plist and add a row with a key called URL Types.
- Expand the URL Typesitem, and Item 0under it and you'll see URL Identifier
- Enter your app's bundle identifier (e.g. com.myCompany.myApp) as the URL Identifiervalue.
- Add another row to Item 0and enter URL Schemes.
- Expand the URL Schemesand under Item 0type in the name for your custom scheme (e.g. myScheme).
- 打开您的应用程序的 Info.plist 并添加一个名为URL Types的键的行。
- 展开URL Types项和其下的Item 0,您将看到URL Identifier
- 输入您的应用程序包标识符(例如 com.myCompany.myApp)作为URL Identifier值。
- 向Item 0添加另一行并输入URL Schemes。
- 展开URL Schemes并在Item 0 下键入自定义方案的名称(例如 myScheme)。
You should now be able to open your app from Safari by typing myScheme://in the address bar. Alternatively, from your app, you can launch the other app like this:
您现在应该可以通过在地址栏中输入myScheme://从 Safari 打开您的应用程序。或者,您可以从您的应用程序启动另一个应用程序,如下所示:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"myScheme://"]];
Note that you can also send parameters to the app you're launching with the url scheme (more on that here).
请注意,您还可以将参数发送到您使用 url 方案启动的应用程序(更多信息请点击此处)。
回答by Praveen
With iOS9 Apple introduced a way to open installed app from Links. Here is the official link for this : Apple universal links
在 iOS9 中,Apple 引入了一种从 Links 打开已安装应用程序的方法。这是官方链接:Apple 通用链接