Search code examples
ioshttp-redirectaffiliate

Make an affiliate link to the iTunes store without redirects?


Apple has explained in "Launching the App Store from an iPhone application" how one can make an affiliate link to the app store and handle the redirect in background so it doesn't annoy the user. But it would be even better not to have the redirect at all. I seem to remember seeing a way to do that, but now I can't find it anywhere.

Is it possible to make an affiliate link from an iOS app to the app store without any redirect at all?

EDIT: To clarify, I am talking about a Linkshare affiliate link.

EDIT 2: I'm getting closer. I have this link, which I grabbed straight off of linkshare's "text links" page. When using k1th's trick below, works without any redirects on the iPad, but still has one redirect on an iPod touch [and presumably iPhone]. I speculate that the redirect may be to switch from top iPad apps to top iPhone apps, but I don't know that for sure.

http://click.linksynergy.com/fs-bin/click?id=sf2bW7QX/qU&offerid=146261.10005745&type=3&subid=0


Solution

  • I take it the reason you don't want redirects is to

    • avoid the Safari browser from popping up
    • avoid redirection within the App Store app itself

    I would prefer k1th's solution, but failing that (I suppose it could fail #2 above), I assume the problem is that the first itms link is not the "final" one. One solution would be to simply hard-code the URL (or provide it by some other means):

    - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
        NSURL myAppUrl = ....
        if ([request.URL.scheme isEqualToString:@"itms"] &&
            [[UIApplication sharedApplication] canOpenURL:myAppURL]) {
            [[UIApplication sharedApplication] openURL:myAppURL];
            return NO;
        }
    
        return YES; // go on redirecting
    }
    

    A cleaner solution would be to read the app ID off the itms link in the request.URL and format a new URL using the pattern that will take you directly to your app.