tags:

views:

424

answers:

3

We have a wifi hotspot that displays a terms of service page before people are allowed to start using it.

After acceptance, a new page with a few links is displayed. I'd like to have those links open in Safari instead of in UIWebView.

I know there's a way to program UIWebView to open links in Safari, but that's not an option as this is the default UIWebView for logging into wifi hotspots and not a custom app.

Is there another way to have the links open in Safari and not in UIWebView? I've tried javascript and I've tried setting the target to _blank.

EDIT: After reading some responses, it seems like the only way to do this is to set the UIWebView delegate. I don't think this is an option because I'm not the one launching the UIWebView.

A: 

Use the openURL method of UIApplication:

NSURL *url = [[NSURL alloc] initWithString:@"http://example.com"];    
[[UIApplication sharedApplication] openURL:url];
[url release];

An Apple example of this is available as part of the LaunchMe sample.

Ben S
A: 

The only way I know how to do this is to set up a UIWebView delegate and supply something like the following:

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
    if (navigationType == UIWebViewNavigationTypeLinkClicked &&
        [request.URL isFileURL] == false)
    {
        [[UIApplication sharedApplication] openURL:request.URL];

        return false;
    }

    return true;
}

The code above will cause Safari to open a link clicked on by the user. I know you said you had little control over this UIWebView -- perhaps you have more than you think by setting the delegate?

fbrereto
`BOOL` values are `YES` and `NO`, not `true` and `false`.
Shaggy Frog
+1  A: 
Jeff Kelley