1

So I'm having a little difficulty setting this up. I'm using this: UIWebView open links in Safari for the code but I can't seem to get it to work.

Here's my .h file:

#import <UIKit/UIKit.h>

@interface SecondViewController : UIViewController
{

}

@property (strong, nonatomic) IBOutlet UIWebView *webView;

@end

And here's my .m file:

#import "SecondViewController.h"

@interface SecondViewController ()

@end

@implementation SecondViewController
@synthesize webView = _webView;

- (void)viewDidLoad
{
    [super viewDidLoad];

    [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http:m.youtube.com/user/haatfilms/uploads"]]];
    [_webView setBackgroundColor:[UIColor clearColor]];
    [_webView setOpaque:NO];
    _webView.scrollView.bounces = NO;
    _webView.scrollView.indicatorStyle = UIScrollViewIndicatorStyleWhite;
}

-(BOOL) webView:(UIWebView *)inWeb shouldStartLoadWithRequest:(NSURLRequest *)inRequest navigationType:(UIWebViewNavigationType)inType {
    if ( inType == UIWebViewNavigationTypeLinkClicked ) {
        [[UIApplication sharedApplication] openURL:[inRequest URL]];
        return NO;
    }

    return YES;
}

@end

And I think I've connected the UIWebView delegate:

webView Delegate

But still, when I click on a link, it still loads in the UIWebView and not in Safari.

Can anyone shed some light as to why it won't work? Thank you so much

Community
  • 1
  • 1
Stickerbox
  • 141
  • 1
  • 12
  • Did you already check this http://stackoverflow.com/questions/2899699/uiwebview-open-links-in-safari – JOM Jan 20 '13 at 01:46
  • I referenced that I used that in my question. After playing with it for a bit though I found that it doesn't work with YouTube, but does with other websites. – Stickerbox Jan 20 '13 at 01:51
  • Yes, YouTube seems to be handled internally by iOS in some different way – JOM Jan 20 '13 at 16:35

1 Answers1

0

Found the problem. Instead of using IB to connect my webView delegate, just do this:

[super viewDidLoad];

    webView.delegate = self;
Stickerbox
  • 141
  • 1
  • 12