开发者

iphone notification from javascript to objective C

开发者 https://www.devze.com 2023-01-04 18:44 出处:网络
I\'ve designed my main view using HTML, 开发者_如何学编程CSS and some images. It looks very nice. I\'m using some images that are clickable in HTML code.

I've designed my main view using HTML, 开发者_如何学编程CSS and some images. It looks very nice. I'm using some images that are clickable in HTML code. On click of some image, I want to load some view accordingly. Is it possible? If yes, please suggest me how to do it. If tutorial or some sample code is available please share it.


Implement the following UIWebView Delegate Method and call your Objective methods

  • (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {

    if (navigationType == UIWebViewNavigationTypeLinkClicked) { NSLog(@"LINK CLICKED......"); //return NO; }

    return YES; }


You can look into PhoneGap for some sample code.

There are two parts. First you define a custom scheme for you application that is only used to communicate between the web page and the delegate. Could just be 'foo:' as it will be private to the page and host. You then handle this custom scheme in the delegate shouldStartLoadWithRequest method and return NO.

With a clickable link, you can just set the href to something that starts with your custom scheme. If you need to send messages at arbitrary times, you can use javascript to set the window.location to a url with your custom scheme.

0

精彩评论

暂无评论...
验证码 换一张
取 消