Reputation: 85
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;
}
Upvotes: 0
Views: 1535
Reputation: 13045
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);
}
}];
Upvotes: 0
Reputation: 11444
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.
Upvotes: 0