Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
319 views
in Technique[技术] by (71.8m points)

iphone - Open iOS app from browser

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.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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. 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).

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...