从浏览器打开 iOS 应用 [英] Open iOS app from browser

查看:53
本文介绍了从浏览器打开 iOS 应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做的是,我们在网站上有一个产品信息.该产品可在商店购买.我们在网站上提供的是产品信息和该产品的一个按钮.

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.

我想对该按钮执行两个操作.当用户在 iPad 或 iPhone 上的 Safari(浏览器)上打开网站并单击 GetProduct 按钮时,必须执行以下两个操作.1. 如果用户已经在设备上安装了产品,则直接在设备中打开应用程序.2. 如果用户没有在设备上安装该应用程序,则将用户链接到商店中的应用程序,以便他可以从那里下载.

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.

我已经处理了第二个条件,但是如何处理第一个条件.如果我已经拥有该应用程序,那么如何通过在浏览器中单击按钮来打开它.

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.

推荐答案

您可以使用 URL 方案.这将使您能够使用应用程序的 url 方案调用 openUrl: 方法,然后该方法将启动您的应用程序.以下是设置自定义网址方案的方法:

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:

  1. 打开您应用的 Info.plist 并添加一行,其中包含一个名为 URL Types 的键.
  2. 展开URL Types 项和其下的Item 0,您将看到URL Identifier
  3. 输入您的应用程序包标识符(例如 com.myCompany.myApp)作为 URL Identifier 值.
  4. Item 0 再添加一行,然后输入URL Schemes.
  5. 展开 URL Schemes,然后在 Item 0 下输入自定义方案的名称(例如 myScheme).
  1. Open your app's Info.plist and add a row with a key called URL Types.
  2. Expand the URL Types item, and Item 0 under it and you'll see URL Identifier
  3. Enter your app's bundle identifier (e.g. com.myCompany.myApp) as the URL Identifier value.
  4. Add another row to Item 0 and enter URL Schemes.
  5. Expand the URL Schemes and under Item 0 type in the name for your custom scheme (e.g. myScheme).

您现在应该可以通过在地址栏中输入 myScheme:// 从 Safari 打开您的应用程序.或者,您可以从您的应用中启动另一个应用,如下所示:

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:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"myScheme://"]];

请注意,您还可以将参数发送到您使用 url 方案启动的应用程序(更多关于 这里).

Note that you can also send parameters to the app you're launching with the url scheme (more on that here).

这篇关于从浏览器打开 iOS 应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆