3

I've got a UIWebView which shows up a couple of screens into a UINavigationController:

First View > Second View > View with UIWebView + UILabel

Now, I display a certain page in that web view, which has a link back to my app....

myapp://foofoo

I know you can set up a custom URL with (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url and some info.plist poking, but how would change the UILabel, which is one the same screen as UIWebView, by simply clicking the myapp://foofoo link?

cannyboy
  • 24,180
  • 40
  • 146
  • 252

2 Answers2

4

The best way to do this would be through a custom link, and then use the UIWebView delegate method -webView:shouldStartLoadWithRequest:navigationType: to trap requests. When you see a request come through with your link in it, you know your action has been triggered.

UIWebView Expose Objective C to JavaScript

Community
  • 1
  • 1
Vjy
  • 2,106
  • 3
  • 22
  • 34
4
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSLog(@"scheme = %@",[[request URL] scheme]);

    if([[[request URL] scheme]isEqualToString:@"myscheme"])
    {
        [messageLabel setText:@"HELLO!"];
        return NO;
    }
    else return YES;
}

Make sure your view controller conforms to the UIWebViewDelegate protocol for this to work.

ySgPjx
  • 10,165
  • 7
  • 61
  • 78
Lee Probert
  • 10,308
  • 8
  • 43
  • 70