Question

I am wondering if this is actually possible,because I am running out of solutions for my problem.The bit.ly short links are just ruining my day lol. The code below is what I am trying to pull off, but this doesn't work with bit.ly links. And it is always detecting bit.ly links first then google redirected links next.

 -(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
if ( inType == UIWebViewNavigationTypeLinkClicked ) {
 if ([[inRequest.URL absoluteString] rangeOfString:@"google"].location==NSNotFound){
        [[UIApplication sharedApplication] openURL:[inRequest URL]];
        return NO;
    }
}
return YES;
}
Was it helpful?

Solution 2

In order to expand the bit.ly link you'll need to make another web service call. LongUrl offers a service to expand shortened URLs. They offer a API to provide this.

You'll just have to live with the extra latency of a second request.

OTHER TIPS

There's also the Bitly API's expand endpoint.

Heres a quick, easy and thread-safe way of getting any short URL to the original URL

Link: https://github.com/emotality/ATURLExpander

Example:

[[ATURLExpander urlEngine] expandURL:@"http://bit.ly/1dNVPAW" withBlock:^(NSError *error, NSString *longURL) {
    if (error) {
        NSLog(@"ATURLExpander ERROR : '%@'", error);
    } else {
        NSLog(@"ATURLExpander URL : '%@'", longUrl);
    }
}];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top