How to open app store from iPhone application

Source: Internet
Author: User

Use the [uiapplicaiont Openurl:] method to open the URL in iTunes to point to the app, song, or album you are interested in.

Follow these steps to obtain the URL:

1. Open iTunes on your Mac.

2. Search for the item you want to link.

3. Right-click or CTR-click the item you are interested in iTunes, and select copy iTunes store URL in the added menu,

Note that the URL you get is a itunes.app.com link, and the iPhone needs a phobourls that can be directly connected,

Therefore, you must perform some conversions.

4. Call [uiapplication Openurl] to open the URL to be modified.

The following is how you open the App Store in your apllication.

Listing 1:Open URL directly

 

 NSString *iTunesLink = @"http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=284417350&mt=8"; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];

Listing 2: Open the URL after Dynamic Modification

 NSString *iTunesLink = @"http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=284417350&mt=8";NSURL *iTunesURL = [NSURL URLWithString:iTunesLink]; // Produce a phobos.apple.com URL that will open the iTunes or App Store application directly[NSURL URLWithString:[NSString stringWithFormat:@"http://phobos.apple.com%@?%@", iTunesURL.path, iTunesURL.query]]; 

 

Some iTunes links, including iTunes affiliate links, result in multiple redirections before reaching the appropriate Store application.
You can process these redirects silently using nsurlconnection, and open the final URL once the redirects are complete.
This allows your application to transition right to the store without launching safari.
Listing 3 demonstrates how to accomplish this.

Note:If you have iTunes links inside a uiwebview,
You can use this technique after intercepting the links with
-[Uiwebviewdelegate webview: shouldstartloadwithrequest: navigationtype:] delegate method.

Listing 3:Sometimes there are many points in an iTunes link. You can use nsurlconnection to open the final URL.

If you have a link in uiwebview, you can complete the link in the [uiwebviewdelegate webview: shouldstartloadwithrequest: navigationtype:] delegate.

 // Process a LinkShare/TradeDoubler/DGM URL to something iPhone can handle- (void)openReferralURL:(NSURL *)referralURL {    NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:[NSURLRequest requestWithURL:referralURL] delegate:self startImmediately:YES];    [conn release];} // Save the most recent URL in case multiple redirects occur// "iTunesURL" is an NSURL property in your class declaration- (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSURLResponse *)response {    self.iTunesURL = [response URL];    return request;} // No more redirects; use the last URL saved- (void)connectionDidFinishLoading:(NSURLConnection *)connection {    [[UIApplication sharedApplication] openURL:self.iTunesLink];}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.