1

Is it possible to handle the call of an URL Scheme inside the same app?

Here's an example: There is an html link in my app that opening would trigger safari. What I want to do is to tap on that link and that no matter where i am in the app a viewcontroller gets pushed with a webview on it.

If this is possible, where I have to do it? If I handle URL Scheme's calls i need to do it on the app's delegate. Where should i do it in this case? If the viewcontroller needs to be pushed, who is the responsible of pushing it? The appdelegate or the view controller thats currently on screen?

Thanks :)

C. K. Young
  • 219,335
  • 46
  • 382
  • 435
tomidelucca
  • 2,543
  • 1
  • 26
  • 26

4 Answers4

2
  1. UITapGestureRecognizer, if your link is in a label:

    UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(openLink:)];
    [yourLinkLabel addGestureRecognizer:gestureRecognizer];
    gestureRecognizer.numberOfTapsRequired = 1;
    gestureRecognizer.cancelsTouchesInView = NO;
    
  2. If it is a link inside a web page loaded in UIWebView, then you can use:webView:shouldStartLoadWithRequest:navigationType. It will be called every time the user taps a link in the UIWebView.

rishi
  • 11,779
  • 4
  • 40
  • 59
1

Please check my Question

I faced the same problem. Hope it will helps you.

Thanks

Community
  • 1
  • 1
Mitesh Khatri
  • 3,935
  • 4
  • 44
  • 67
0

Well its kind of annoying to involve view controller. I found it easier to use javascript to load new links/content within the page. That way one webview is involved and the data/html files get shuffled. Let me know if you need more information.

Mike
  • 122
  • 7
0

Try this. Use this code in the current controller

WebViewController *objWebViewController     =   [[WebViewController alloc] initWithNibName:@"WebViewController" bundle:nil];
                objWebViewController.m_strHtml=[NSString stringWithString:@"www.google.com"];//m_strHtml is a NSString variable in WebViewController class
                [self.navigationController pushViewController:objWebViewController animated:YES];
                [objContentWebViewController release];

Use this in the WebViewController

NSURL *url = [[NSURL alloc] initWithString:m_strHtml];
        NSURLRequest * req = [[NSURLRequest alloc] initWithURL:url];
        [url release];
        [Webview loadRequest:req];
        [req release];

ELse you can load the the html inside a web view and the web view opens the links inside it
as default . Use the following code.

m_strHtml=[[NSString alloc]initWithFormat:@"<html><body>%@</body></html>",m_strHtmlContent];//m_strHtmlContent is string variable to store the html content

        [Webview loadHTMLString:m_strHtml baseURL:Nil]; 
        Webview.backgroundColor=[UIColor clearColor];
Melbourne
  • 531
  • 3
  • 24