Under the Bridge

Snippet: App Store Links

[UPDATE: How did you get here? This is way obsolete — go read iTunes Affiliate Changes!]

So, you ever wondered how to get your iPhone “Lite” app to trigger the App Store to load the full version’s page? And you didn’t stumble across QA1629? Well, here’s the quick notes version for you.

Step 1: Copy the URL of your full app from the App Store by right-clicking its name, which will be something like


Step 2: Replace “itunes” with “phobos”. This is so it doesn’t start Safari.


Step 3: Have the system load it.

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

Ah, but what if you want to use your iTunes affiliate account? After all, no point leaving 5% off the table! Well, that’s a trifle more complicated, since there’s redirects involved. So take your big long LinkShare string, change “itunes” to “phobos” as above, and create a NSURLConnection to sort out the URL that actually needs to be loaded. Like this:

- (IBAction)buyFullVersion
   NSString *referralLink = @"http://click.linksynergy.com/yadayadayada";
   self.iTunesURL = [NSURL URLWithString:referralLink];
   NSURLRequest *referralRequest = [NSURLRequest
   NSURLConnection *referralConnection = [[NSURLConnection alloc]
   [referralConnection release];

// Save the most recent URL in case multiple redirects occur
- (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.iTunesURL];

And that, dear friends, is how you get 75% instead of 70% on your in-app referrals. You’re welcome.


This followup post dicusses analytics, localization, and other Linkshare goodies!

  • Shiv

    Hi Alex,

    This is really interesting.

    I was reading up on the iTunes Affliate Program after reading your blog. It was not clear whether the referrals to the AppStore is eligible for commission or not. Reading it seemed it was only for the iTunes. There was a link to an Apple Store Affliate program but i was not sure if it was the AppStore on the iPod/iPhone or not.

    http://www.apple.com/itunes/affiliates/faq.html#earning —-

    *Why don’t I see my commission?*

    As an iTunes Affiliate, you will earn commission on sales generated on the U.S. iTunes Store. Links to the Apple Online Store or an international iTunes Store do not earn commission through the U.S. iTunes Affiliate Program. To earn commission on Apple Online Store sales, join the Apple Store Affiliate Program. To earn commission on international iTunes Store sales, apply to join the iTunes Affiliate Program in Europe, Japan, Australia, or New Zealand.

    Apply to join the iTunes Affiliate Program in the U.S., Europe, Japan, Australia, or New Zealand.

    Apply to join the Apple Store Affiliate Program.


    Can you comment on this?



  • http://www.alexcurylo.com/ Alex

    Well, I don’t know yet, but since I looked into this for the lite version of a little sound player I did for a fellow in Chicago,


    once the lite version’s up, which if I get the graphics today should be about a week, you can click on the upgrade button and invest $1.99 in finding out!

    ‘Course, I’m Canadian so I’m signed up with LinkShare UK, so that might throw things off.

  • Kev

    Alex, did you ever find out if this works for referrals to the App Store? (Shiv’s question)

  • http://www.alexcurylo.com/ Alex

    Yes, Kev, apparently indeed it does: about a month and a half ago I got a LinkShare referral cheque for a big $50.99. W00t!

    I haven’t bothered signing up with any advertisers other than iTunes, and I haven’t put referral links anywhere other than the source described in this post and occasionally in the blog here, and every single referral link has been directly to an App Store app. So that cheque is definitive proof that at least one or the other of those strategies does actually bring in a few pennies here and there.

    Which reminds me, I saw a reference somewhere or other to theoretically being able to futz with your referral links to be able to determine the source of your referral monies. I should dig into that. It’ll be another blog post in the next couple days or so probably if I do manage to track it down!

  • Pingback: LinkShare analytics at Under The Bridge()

  • http://www.denvog.com DenVog

    Hi Alex. Thanks for sharing this. I am trying to pull my URL from a dictionary file, instead of hard coding them. Can you tell me why this doesn’t work? I have changed “itunes” to “phobos” and it opens in Safari (buyUrlString is pulled from a dictionary).
    – (void)openLinkShareURL
    NSString *referralLink = (@”%@”, buyUrlString);
    self.iTunesURL = [NSURL URLWithString:referralLink];
    NSLog(@”link: %@”, referralLink);
    NSURLRequest *referralRequest = [NSURLRequest requestWithURL:self.iTunesURL];
    NSURLConnection *referralConnection = [[NSURLConnection alloc] initWithRequest:referralRequest delegate:self startImmediately:YES];
    [referralConnection release];

    If I copy and paste the same URL so that it is hard-coded like your example, then it does work. I’m stumped.

  • http://www.alexcurylo.com/ Alex

    My guess would be that you’re running into issues with the HTML of the intended link conflicting with the XML encoding of the plist (by “dictionary file” you mean a plist, right)? I ran into that problem in a different context. Unfortunately I’m way too busy to try remembering where exactly and track down what I did about it, but that should get you started figuring out the problem I trust.

  • http://www.denvog.com DenVog

    Yes. By “dictionary” I mean plist. Thanks for taking time to reply and provide the suggestions. It at least gives me some idea what to look for. Thanks.

  • http://www.denvog.com DenVog

    Hi Alex. Have you experienced any issues with links to Movies or TV Shows on v2.x devices? Using an iPod touch with 2.2.1, I’m able to get Albums and Podcast to work, but links to Movies and TV Shows redirect to Safari and result in “Can’t connect to iTunes Store”. While everything works on an iPhone with v3.1.2 running the same version of the same application with the same links on both devices.

  • http://www.alexcurylo.com Alex

    Sorry Denvog, I’ve only done links to applications and songs/albums so far. Don’t know why other kinds of links would work any different, but it’s always possible to be surprised.

    But since anybody who hasn’t upgraded to 3.x by now likely isn’t a big shopper anyways, I wouldn’t get overly worried about it!

  • http://www.denvog.com DenVog

    I’m relieved, and slightly embarrassed, that I figured it out. Not an issue with the links, or my code. Apparently the iTunes app in iPhone OS v2.x does not support the download of Movies or TV shows. Guess that wasn’t added until later…

  • http://www.alexcurylo.com Alex

    Heh. That would explain it :)

  • Deepthi

    Hi Alex

    I tried the first process to connect to the iTunes AppStore and to open the same application u mentioned in that link, but it is not opening on my iPhone. It is showing an alert saying that “Cannot Open Page” with the message “Safari cannot open the page because too many redirects occoured.”. Can you please help me on this.

    Thanks in Advance

  • http://www.alexcurylo.com/ Alex

    Hey Deepthi,

    I just checked the app and it’s still working as expected, so I’d imagine something’s going wrong with your delegation. Put a breakpoint in your -willSendRequest to make sure it’s getting called, and NSLog() the value of self.iTunesURL in your -connectionDidFinishLoading.

    If all is working as intended, the value of self.iTunesURL that you actually open, which is the current one when -connectionDidFinishLoading gets called, should not redirect at all. You can check that by pasting it into Safari directly.

    My guess would be that a misspelling crept into your -willSendRequest definition so the URL is not actually being updated as part of the redirection.

  • http://www.tuzzolotron.com Matt

    Hey Alex,

    Did you encounter any trouble w/ the response in -willSendRequest being nil? I’ve set a breakpoint there and the response is always nil. I’ve verified that I’m getting a 301 by curling the URL in question and checking out the headers.

    Any ideas why that might be happening?



  • http://www.alexcurylo.com Alex


    I’d guess that the URL must be malformed in some way. Here’s the latest version of the referral code which I see on the LinkShare dashboard is definitely working fine as of yesterday:

    – (void)sendReferral:(NSString *)appID tagged:(NSString *)tag
    NSString *referralTemplate1 = @”http://click.linksynergy.com/fs-bin/stat?id=goXYUj1aTb0&offerid=146261&type=3&subid=0&u1=”;
    NSString *referralTemplate2 = @”&tmpid=1826&RD_PARM1=http%3A%2F%2Fphobos.apple.com%2FWebObjects%2FMZStore.woa%2Fwa%2FviewSoftware%3Fid%3D”;
    NSString *referralTemplate3 = @”%26mt%3D8%26partnerId%3D30″;
    NSString *referralLink = [NSString stringWithFormat:@”%@%@%@%@%@”, referralTemplate1, tag, referralTemplate2, appID, referralTemplate3];
    self.iTunesURL = [NSURL URLWithString:referralLink];
    NSURLRequest *referralRequest = [NSURLRequest requestWithURL:self.iTunesURL];
    NSURLConnection *referralConnection = [[NSURLConnection alloc] initWithRequest:referralRequest delegate:self startImmediately:YES];
    [referralConnection release];

    called with something like

    [self sendReferral:@”302877146″ tagged:@”PosesOld”]; // volume 1 to test

    Try that exact code. If it doesn’t work, I have no idea why, there must be something strange about your network setup. If it does, then editing it for your account ought to work too…

  • http://www.magicsolver.com/ Oliver

    Thanks for sharing this code. However, I think you have a bug in your connection:willSendRequest:redirectResponse: method. I believe the middle line should be:
    self.iTunesURL = [request URL];

    Instead of:
    self.iTunesURL = [response URL];

    If you check the docs (http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/Reference/Reference.html#//apple_ref/occ/instm/NSObject/connection:willSendRequest:redirectResponse), you’ll see that the response argument actually contains the URL for the object that caused the redirect (i.e. the URL you’re being redirected from, not to). I believe this is why one of the previous posters was getting Safari popping up briefly, as the iTunesURL property is being set back to LinkShare before the app closes.

    Hope that helps! Do feel free to correct me if I’ve made a mistake there…


  • http://www.alexcurylo.com/ Alex

    Hmmmm. Yes, Oliver, that’s what I read in the docs too …

    … but using [response URL] is taken straight from QA1269


    and I’m moderately tended to think that an error there wouldn’t have made it through review. (Certainly not impossible though!) Soon as I have a spare minute, I’ll do some digging into exactly what the URLs are on both side in some actual redirects and file a Radar probably if it does look like an error in the QA.

    But if you feel like possibly blowing a tech support incident (if it is their error, they often refund the incident) to find out for sure whether QA1629 is broken or not, please share the results!

  • http://www.alexcurylo.com/ Alex

    Late update for anyone reading this thread:

    The reason that the QA1269 version is correct is that you actually don’t want to open the very last resolved URL, which will be a straight iTunes link, like


    You actually want to open the URL in the response that resolved to that, which will be something like


    The significant difference, of course, is that your LinkShare affiliate arguments are in that one. You want those.

  • Geri

    It links to your LinkShare account? Tricky one.

  • Geri

    Forget it, now I understand.