Intercept url and open url in Safari

I intercepted the url by doing the following:

- (BOOL)openURL:(NSURL *)url{
    URLViewController * web = [[URLViewController alloc] init];
    web.url = url;
    UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:web];
    [nav.navigationBar setTintColor:[UIColor blackColor]];
    [nav setModalPresentationStyle:UIModalPresentationFormSheet];
    [self.detailViewController presentModalViewController:nav animated:NO];
    [web release];
    [nav release];
    return YES;
}

I have a UITextView in which a URL is found, and when I click on the URL, a link opens in ModalViewController. Detailed information on what is happening can be seen here. Now the problem is that if I want to open the URL in safari, is that possible?

+3
source share
1 answer

You should add a flag overrideindicating whether you want to control or not.

@interface MyApplication : UIApplication {

}

-(BOOL)openURL:(NSURL *)url withOverride:(BOOL)override;

@end

@implementation MyApplication


-(BOOL)openURL:(NSURL *)url withOverride:(BOOL)override {
    if ( !override ) {
        return [super openURL:url];
    }

    if  ([self.delegate openURL:url]) {
        return YES;
    } else {
        return [super openURL:url];
    }
}

-(BOOL)openURL:(NSURL *)url{
    return [self openURL:url withOverride:YES];
}
@end

So, now all the calls that you want to get around can be sent this way.

[[MyApplication sharedApplication] openURL:url withOverride:NO];

Original answer

This is what you should do. Place it in front of the operator return YES;.

if ( [super canOpenURL:aURL] ) {
    return [super openURL:aURL];
}
+4

All Articles