I am using IFTweetLabel and have it to the point were it recognizes links but I am having an awful time opening a webview with the button IFTweetLabel creates. I a running the NSLog and can clearly see it is understanding each link when the button is presses but it will not open the URL for some reason .
Below is the code I am using to show the view and load the string in a webView....which all works besides the loading of the webview.
Any suggestions would be very much appreciated! thank you!
- (void)handleTweetNotification:(NSNotification *)notification
{
[UIView beginAnimations:@"animateView" context:nil];
[UIView setAnimationDuration:1.0];
CGRect viewFrame = [MainwebView frame];
viewFrame.origin.x = 220;
MainwebView.frame = viewFrame;
MainwebView.alpha = 1.0;
web.alpha = 1.0;
MainwebView.layer.shadowColor = [[UIColor blackColor] CGColor];
MainwebView.layer.shadowOffset = CGSizeMake(1.0f, 1.0f);
MainwebView.layer.shadowRadius = 8.0f;
MainwebView.layer.shadowOpacity = 1.0f;
[self.view addSubview:MainwebView];
[UIView commitAnimations];
[web loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:tweetLabel.text]]];
NSLog(@"handleTweetNotification: WTF notification = %@", notification);
}
Here's my code which should work well, but also should be cleaned up some:
- (void)handleTweetNotification:(NSNotification *)notification {
unichar theChar = [(NSString *)notification.object characterAtIndex:0];
NSString *theString = (NSString *)notification.object;
if ( [[NSString stringWithCharacters:&theChar length:1] isEqualToString:@"#"]) {
DLog(@"This is a hashtag");
theString = [theString stringByReplacingOccurrencesOfString:@"#" withString:@"%23"];
NSURL *hashtagURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://twitter.com/#!/search?q=%@", theString]];
WebViewController *theWebVC = [[WebViewController alloc] init];
theWebVC.request = [NSURLRequest requestWithURL:hashtagURL];
UINavigationController *theNavigationVC = [[UINavigationController alloc] initWithRootViewController:theWebVC];
[self presentModalViewController:theNavigationVC animated:YES];
}
if ( [[NSString stringWithCharacters:&theChar length:1] isEqualToString:@"@"]) {
DLog(@"This is a Mention");
theString = [theString stringByReplacingOccurrencesOfString:@"@" withString:@""];
NSURL *mentionURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://twitter.com/%@", theString]];
WebViewController *theWebVC = [[WebViewController alloc] init];
theWebVC.request = [NSURLRequest requestWithURL:mentionURL];
UINavigationController *theNavigationVC = [[UINavigationController alloc] initWithRootViewController:theWebVC];
[self presentModalViewController:theNavigationVC animated:YES];
}
if ( [[NSString stringWithCharacters:&theChar length:1] isEqualToString:@"h"]) {
DLog(@"This is a hyperlink");
theString = [[theString componentsSeparatedByString: @"\n"] objectAtIndex:0];
NSURL *hyperlinkURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@", theString]];
WebViewController *theWebVC = [[WebViewController alloc] init];
theWebVC.request = [NSURLRequest requestWithURL:hyperlinkURL];
UINavigationController *theNavigationVC = [[UINavigationController alloc] initWithRootViewController:theWebVC];
[self presentModalViewController:theNavigationVC animated:YES];
}
}