1

I want to launch iTunes via my app. Currently there's a code that's doing that using [NSURLConnection alloc] initWithRequest. I'm thinking about changing it to [UIApplication sharedApplication] openURL.

What is the difference and what is the correct way?

YogevSitton
  • 10,068
  • 11
  • 62
  • 95
  • Did you check what these two functions do when you call them? Hold ALT and select the methods name by clicking on it or double click to get to apples documentation. – Alex Cio Jul 23 '15 at 15:31

3 Answers3

1

[UIApplication sharedApplication] openURL used when you need go to another app. In your case its AppStore

iOS Developer Library

Discussion: The URL can locate a resource in the same or other app. If the resource is another app, invoking this method may cause the calling app to quit so the other one can be launched.

Community
  • 1
  • 1
1

Q: How do I launch the App Store from my iOS app? Also, how do I link to my application on the store?

A: The -[UIApplication openURL:] method handles links to applications and media by launching the appropriate store application for the passed NSURL object. Follow the steps below to obtain a link to an application, music, movie, or TV show sold on iTunes, and link to it from your iOS application:

Launch iTunes on your computer. Search for the item you want to link to. Right-click or control-click on the item's name in iTunes, then choose "Copy iTunes Store URL" from the pop-up menu. In your application, create an NSURL object with the copied iTunes URL, then pass this object to UIApplication' s openURL: method to open your item in the App Store.

Listing 1 Launching the App Store from an iOS application

NSString *iTunesLink = @"https://itunes.apple.com/us/app/apple-store/id375380948?mt=8";
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];

see https://developer.apple.com/library/ios/qa/qa1629/_index.html

Nik Yekimov
  • 2,657
  • 2
  • 24
  • 34
1

1.[NSURLConnection alloc] initWithRequest: is a way of network request. you use it if you want to get some data from network

2.[UIApplication sharedApplication] openURL: can open an app according to the param.

  1. I guess you may want to use [UIApplication sharedApplication] openURL:
Alex Cio
  • 6,014
  • 5
  • 44
  • 74