2

If I make a UIWebView, I can just go to the url of the app on the web, but that does not seem to make complete sense since the app store is accessible on the device.

Is there a "preferred" or common way people link to other apps from within apps?

Thanks!

Genadinik
  • 18,153
  • 63
  • 185
  • 284

2 Answers2

3

You have to launch the system browser (Safari) with the URL of the AppStore entry of your other App, then what would happen is that the user would see how Safari opens, and suddenly the AppStore launches in front of it with the selected App information...

NSString *url = @"http://AppStore.com/<app_id_here>";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];

Hope this is what you are looking for...

apascual
  • 2,970
  • 1
  • 20
  • 32
  • thank you. Should I do this from a UIWebView? And from which function in the controller is it best to do this? – Genadinik Feb 20 '13 at 12:47
  • Sure, you can do it in a UIWebView, in that case you should implement "shouldStartLoadWithRequest" in your controller and then perform the launch when the url changes... I just gave you an example here: http://stackoverflow.com/questions/14979457/ios-web-view-after-a-click-how-to-open-a-page-in-a-web-browser-instead-of-emb/14979513#14979513 – apascual Feb 20 '13 at 12:50
  • No need to create a UIWebView for this - everything view-related is handled outside your app. – Rok Jarc Feb 20 '13 at 12:51
  • Probably he already have a UIWebView and wants to know if he can use it for this purpose :-) – apascual Feb 20 '13 at 12:52
3

I link all my apps to themselves on the App Store so that users can 'Rate on the App Store'.

This is how I do it (using the itms-apps: prefix):

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:
                                                @"itms-apps://itunes.apple.com/app/gift-idea+/id561981438?mt=8"]];

Make sure to amend the link with your own. You can get the link from iTunes by selecting the arrow next to price and then Copy Link.

You can put this code where ever you want to open the app in the App Store. If you are putting the link in a HTML file (which I am not 100% sure if you can) to use in a webView I would strongly suggest you have a fallback for users who are not using an iOS device (that is if your website file is on the internet and not local to the app).

You may find this document helpful for URL Scheme Reference.

Patrick
  • 6,495
  • 6
  • 51
  • 78
  • thank you - are you doing this from the viewDidLoad method? Or another method like viewDidAppear? – Genadinik Feb 20 '13 at 13:02
  • 1
    I have it in `didSelectRowAtIndexPath` and have also used it in a `UIButton`'s action. – Patrick Feb 20 '13 at 13:03
  • Thank you, didn't know this... What's the difference between this and "http://" prefix? – apascual Feb 20 '13 at 13:05
  • The iOS device will open a http:// url in its web browser which (if it is a link to an app) will automatically redirect to the app store (which is horrible). The `itms-apps:` prefix lets the device know to open the App Store directly. – Patrick Feb 20 '13 at 13:07
  • Good luck. Make sure to check out the Apple documents on this (which I have added to my answer). – Patrick Feb 20 '13 at 13:15
  • @Patrick would this not work in the emulator since I am trying to open itunes? – Genadinik Feb 20 '13 at 13:29
  • This is not doing anything: [[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"itms://itunes.com/apps/my_dev_name"]]; – Genadinik Feb 20 '13 at 13:30
  • 1
    the prefix is `itms-apps:` not `itms:` and yes, it won't work on the Simulator as the App Store is not installed on it. – Patrick Feb 20 '13 at 13:35