`
zl4393753
  • 浏览: 340358 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

Launching the App Store from an iPhone application

 
阅读更多
Q:  How do I launch the App Store from my iPhone application? 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, song, or album sold on iTunes, and link to it from your iPhone 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.
Open the modified URL using an NSURL object and the -[UIApplication openURL:] method.
Note: You can also use the iTunes Link Maker tool to get a link to an application, song, or album sold on iTunes. See iTunes Link Maker FAQ to learn more about that tool.
See Listing 1 for an example that launches the App Store from a native application.

Listing 1  Launching the App Store from an iPhone application.
NSString *iTunesLink = @"http://itunes.apple.com/us/app/id284417350?mt=8";

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:iTunesLink]];
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 2 demonstrates how to accomplish this.

Note: If you have iTunes links inside a UIWebView, you can use this technique after intercepting the links with the -[UIWebViewDelegate webView:shouldStartLoadWithRequest:navigationType:] delegate method.
Listing 2  Processing iTunes Affiliate links in an iPhone application.
// Process a LinkShare/TradeDoubler/DGM URL to something iPhone can handle
- (void)openReferralURL:(NSURL *)referralURL
{
    NSURLConnection *con = [[NSURLConnection alloc] initWithRequest:[NSURLRequest requestWithURL:referralURL] delegate:self startImmediately:YES];
    [con 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];
    if( [self.iTunesURL.host hasSuffix:@"itunes.apple.com"])
    {
        [connection cancel];
        [self connectionDidFinishLoading:connection];
        return nil;
     }
     else
     {
       return request;
     }
}

// No more redirects; use the last URL saved
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
    [[UIApplication sharedApplication] openURL:self.iTunesURL];
}
分享到:
评论

相关推荐

    CS193P IOS APPLICATION DEVELOPMENT Assignment 1 Walkthrough.pdf

    This involves accepting an invitation to join the iPhone University Developer Program and downloading the necessary software from Apple's developer website. - **Importance:** Having the latest SDK...

    developing android application with adobe air.part3.rar

    Launching an AIR Application Monetizing Your Application Reporting Conclusion Chapter 5 : Evaluating Device Capabilities and Handling Multiple Devices Hardware Software Creating Content for Multiple ...

    Get_the_Window

    Get the Window Title, Active Document, and tell if an App is Running after Shell Launching It Description: This application demonstrates how to get the window title of an application you started with ...

    developing android application with adobe air.part1

    Launching an AIR Application Monetizing Your Application Reporting Conclusion Chapter 5 : Evaluating Device Capabilities and Handling Multiple Devices Hardware Software Creating Content for Multiple ...

    developing android application with adobe air.part4.rar

    Launching an AIR Application Monetizing Your Application Reporting Conclusion Chapter 5 : Evaluating Device Capabilities and Handling Multiple Devices Hardware Software Creating Content for Multiple ...

    developing android application with adobe air.part2.rar

    Launching an AIR Application Monetizing Your Application Reporting Conclusion Chapter 5 : Evaluating Device Capabilities and Handling Multiple Devices Hardware Software Creating Content for Multiple ...

    Electron桌面app实战

    2. **Electron API**:Electron提供了丰富的API,如`app`、`browserWindow`、`menu`和`tray`,这些都是构建桌面应用的核心工具。 3. **Node.js集成**:由于Electron基于Node.js,我们可以直接在应用中使用Node模块...

    This is an ActiveX DLL that causes a client app to wait for

    This is an ActiveX DLL that causes a client app to wait for another... The library takes care of launching the new app and doing all of the synchronization. It also returns the exit code for the process.

    Troubleshooting.Xcode.1484215613

    Troubleshooting Xcode is a handbook for software developers of all levels creating applications for iOS and OS X using... Check the version of an app on the App Store Chapter 48. Power tips: Beyond Xcode

    Understanding the Overheads of Launching CUDA Kernels.pdf

    理解CUDA核启动开销 在GPU计算领域,CUDA核(Kernel)扮演着至关重要的角色。然而,在启动CUDA核时,存在着许多潜在的开销,这些开销可能会对程序的性能产生影响。因此,了解和理解CUDA核启动开销对于优化GPU计算...

    The Launching Framework in Eclipse

    ### Eclipse中的启动框架 #### 概述 在集成开发环境(IDE)中,启动(运行或调试)正在开发中的代码的能力是基本且重要的。由于Eclipse更多地被视为一个工具平台而非单一工具,其启动功能完全依赖于当前安装的插件...

    Quantum Computing:An Environment for Intelligent Large Scale Real Application

    It discusses how the advances in quantum computing and quantum physics have allowed the building, launching and deploying of space exploration systems that are capable of more and more as they become...

    VB编程资源大全(英文源码 API)

    store and save a password to the registry and also encrypts it to keep out prying eyes.<END><br>32,delay.zip This is a rough translation of the GetTickCount API and includes three different ways to...

    源码Deployment with Docker_ Apply continuous integration models, deploy app

    What you will learnSet up a working development environment and create a simple web service to demonstrate the basicsLearn how to make your service more usable by adding a database and an app server ...

    MrFu-ArcMenu

    If you want to use this library you must before all indicate to your application that you want to use it by launching the following command from the root directory of your application $ android ...

Global site tag (gtag.js) - Google Analytics