Make an affiliate link to the iTunes store without redirects?

我是研究僧i 提交于 2019-12-09 06:15:32

问题


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


回答1:


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.




回答2:


Yes, you may have slashes in the params (that's because it's a slash after the question mark starting the parameter part of the URL.

Regarding skipping Mobile Safari to process the affiliate links:

You can either set up a hidden UIWebView to handle the redirect or do all that in the URL loading system yourself. This is with a hidden WebView:

NSURLRequest *r = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://click.linksynergy.com/fs-bin/click?id=sf2bW7QX/qU&offerid=146261.431296703&type=2&subid=0"]];

testWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)];
testWebView.hidden = YES;
testWebView.delegate = self;
[testWebView loadRequest:r];

the delegate:

#pragma mark - UIWebViewDelegate

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {

    if ([request.URL.scheme isEqualToString:@"itms"] &&
        [[UIApplication sharedApplication] canOpenURL:request.URL]) {
        [[UIApplication sharedApplication] openURL:request.URL];
        return NO;
    }

    return YES; // go on redirecting
}

testWebView needs to be an instance var and the view controller itself needs to be a <UIWebViewDelegate>. You also need to set the webview delegate to nil somewhere (e.g. in -dealloc)




回答3:


There is a much cleaner solution directly from Apple here: https://developer.apple.com/library/ios/#qa/qa1629/_index.html

And for brevity, here is the code from that page:

// 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.iTunesURL];
}



回答4:


I found this document and I think it's giving me the answer. I always have a hard time deciphering these things, but I think it says that what I do is start with a basic link:

http://itunes.apple.com

then append a partnerId of 30, plus my linkshare affiliate token, which I think is

sf2bW7QX/qU

to end up with the following:

http://itunes.apple.com?partnerId=30&id=sf2bW7QX/qU

I got what I think is my id by following the instructions in the Apple doc, which basically say to grab the id parameter from a random linkshare link. The link I used for the purpose was this:

<a href="http://click.linksynergy.com/fs-bin/click?id=sf2bW7QX/qU&offerid=146261.431296703&type=2&subid=0"><IMG border=0 src="http://a464.phobos.apple.com/us/r30/Music/b9/7f/91/mzi.kbjyfypr.170x170-75.jpg" ></a><IMG border=0 width=1 height=1 src="http://ad.linksynergy.com/fs-bin/show?id=sf2bW7QX/qU&bids=146261.431296703&type=2&subid=0" >

I'm still quite unsure about the whole thing. Can my linkshare affiliate token really have a slash in it?




回答5:


This answers your question: http://www.apple.com/itunes/affiliates/resources/documentation/linking-to-the-itunes-music-store.html#apps

BTW, I find this whole affiliate program too complicated. I looked into it and I don't think it's worth the 5% commission.



来源:https://stackoverflow.com/questions/8548984/make-an-affiliate-link-to-the-itunes-store-without-redirects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!