简体   繁体   中英

Open Link in UIWebview not UIShared Application

I have been having a rough time trying to open links that a user clicks in a simple web view instead of multitasking and going to safari. It is quite a pain for my users to have to leave the app every time a link is clicked and I know it is probably quite simple but still am having a terrible time making this happen. Here is the code I am using but still when the link is clicked it opens safari.

If anyone can help point me in the right direction I would be greatly appreciative! Thank you!

     - (void) handleURL:(NSURL*)url
    {  
    [web loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"%@"]]];
    }


    - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest 
*)request  
    navigationType:(UIWebViewNavigationType)navigationType {
    NSLog(@"expected:%d, got:%d", UIWebViewNavigationTypeLinkClicked, navigationType);
    if (navigationType == UIWebViewNavigationTypeLinkClicked) {
    [UIApplication sharedApplication] ;
    return NO;
    }
    if (navigationType == UIWebViewNavigationTypeLinkClicked) {    
   [web loadRequest:[NSURLRequest requestWithURL:[NSURL 
    URLWithString:replyTweetText.text]]];    
    return YES;
    }

    }

I'm not sure what this bit does:

if (navigationType == UIWebViewNavigationTypeLinkClicked) {
    [UIApplication sharedApplication] ;
    return NO;
    }

The line [UIApplication sharedApplication]; creates and returns the singleton application instance. You aren't doing anything with it.

Also, both if statements are identical, so only the first will ever be hit and the method returns NO . There is no default returned value, which is bad for a non-void function. Try this instead:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    return YES;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM