2012-05-02 51 views
1

我已经在我的应用程序中使用Linkshare链接了一段时间了。它工作正常。 我实施了苹果的建议,以吸收任何重定向并呼叫最后一个URL。从内部应用程序打开GeoRiot友情链接?

对于那些正在寻找它的人,HERE IT IS

我有链接到调用此方法一个UIButton:

[self openReferralURL:[NSURL URLWithString:link]]; 

其中的链接是一个的NSString与下面的值(我LinkShare的链接)

@“HTTP://点击.linksynergy.com/FS斌/ STAT?ID = Jexmk6JU * OU & OFFERID = 146261 &类型= 3 &的子ID = 0 & tmpid = 1826 & RD_PARM1 = HTTP%253A%252F%252Fitunes.apple.com%252FWebObjects%252FMZStore .woa%252Fwa%252FviewSoftwa %253Fid%253D353970672%2526partnerId%253D30“

这工作正常。当我点击按钮时,它会立即启动App Store应用程序而无需首先打开Safari。

但是当我改变链接到下面的GeoRiot链接时,它首先打开Safari,然后只打开App Store。我想不出为什么会这样做。

@“http://target.georiot.com/Proxy.ashx?grid=5700 & ID = Jexmk6JU * OU & OFFERID = 146261 &类型= 3 &的子ID = 0 & tmpid = 1826 & RD_PARM1 = HTTP%253A%252F%252Fitunes.apple.com%252FWebObjects%252FMZStore.woa%252Fwa%252FviewSoftware%253Fid%253D353970672%2526partnerId%253D30"

任何人都可以帮助吗?你能分享你的geotarget链接与我的比较? 无论如何,我有1个UIWebview,打开一个带有Geotarget链接的网页,并且 工作正常(即直接打开App Store应用程序)。

我现在没有想法。我认为问题可能在于GeoRiot链接,但我有 不知道为什么或者我应该做什么,因为使用Linkshare链接它工作正常。

+0

我讨厌它发生这种情况。在我发布这个问题后,我解决了它。 – GeneCode

+0

你能告诉我们吗?我很感兴趣...... – Andrea

+0

当然安德烈,请参阅下面的答案以获取解决方案。 – GeneCode

回答

1

我一直在问的问题,并回答了他们很多这些天,但安德烈,这里有云:

对于那些你谁使用georiot链接,这些方法/功能会有效 很好,而不是苹果示例代码。

// Process a URL to something iPhone can handle 
- (void)openReferralURL:(NSURL *)referralURL 
{ 
    NSURLRequest *theRequest=[NSURLRequest requestWithURL:referralURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30.0]; 
    NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; 
    [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 
{ 


    if (response) { 
     NSMutableURLRequest *r = [[request mutableCopy] autorelease]; // original request 
     [r setURL: [request URL]]; 


     self.iTunesURL = [r URL]; 

     if ([self.iTunesURL.host hasSuffix:@"itunes.apple.com"]) { 

      [[UIApplication sharedApplication] openURL:self.iTunesURL]; 

     } 


     return r; 
    } else { 
     return request; 
    } 

} 

并使用,只要致电:

[self openReferralURL:[NSURL URLWithString:@"http://target.georiot.com/Proxy.ashx?grid=5700&id=Jexmk6JU*OU&offerid=146261&type=3&subid=0&tmpid=1826&RD_PARM1=http%253A%252F%252Fitunes.apple.com%252Fus%252Fapp%252Fiquiksplash-pro-all-in-one%252Fid378458261%253FpartnerId%253D30"]]; 

也许你也应该使用URL缩短服务工具来清理长URL一塌糊涂,但无论哪种方式,它工作正常。

+0

谢谢! Apple Q&A中的原始代码也适用于我。只是做了一个小的改变,使其兼容ARC ... – Andrea

0

你发现itunes的网址没关系。

你有http://itunes.apple.com地址,ssl重定向问题呢? 因为itunes门户将重定向你的https://itunes.apple.com地址。 我还改进了您的if iTunes分支部分。

 
// Process a URL to something iPhone can handle 
- (void)openReferralURL:(NSURL *)referralURL 
{ 
    NSURLRequest *theRequest=[NSURLRequest requestWithURL:referralURL 
               cachePolicy:NSURLRequestUseProtocolCachePolicy 
              timeoutInterval:30.0]; 

    NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; 
    [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 
{ 
    if (response) { 
     NSMutableURLRequest *r = [[request mutableCopy] autorelease]; // original request 
     [r setURL: [request URL]]; 

     NSURL *iTunesUrl = [r URL]; 
     NSLog(@"Processing affiliate link : %@", iTunesUrl); 
     if ([[iTunesUrl absoluteString] hasPrefix:@"https"] && [iTunesUrl.host hasSuffix:@"itunes.apple.com"]) { 
      [[UIApplication sharedApplication] openURL:iTunesUrl]; 
     }   
     return r; 
    } else { 
     return request; 
    } 
} 

相关问题