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

查看:147
本文介绍了从浏览器打开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.

我想对该按钮采取两个操作。
当用户在Safari(浏览器)上的iPad或iPhone上打开网站并单击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并添加一行名为<的键strong>网址类型。

  2. 展开网址类型项目,并在其下展示项目0 ,您会看到网址标识符

  3. 输入您应用的套装标识符(例如com.myCompany.myApp)作为网址标识符值。

  4. 将另一行添加到项目0 并输入网址结构

  5. 展开网址套餐并在项目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://"]];

请注意,您还可以使用网址方案向您启动的应用发送参数(详情请参阅此处)。

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天全站免登陆