使用JavaScript从UIWebView进行调用操作 [英] Call action from UIWebView with JavaScript

查看:94
本文介绍了使用JavaScript从UIWebView进行调用操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建一个简单的应用程序,以将图像上传到我的网站.我正在使用本教程: http://www.youtube.com/watch?v=aQXaJO36I7Y

I am trying to build a simple app that uploads images to my site. I am using this tutorial: http://www.youtube.com/watch?v=aQXaJO36I7Y

我想做什么,而不是使用应用程序界面中的按钮,我想在Webview网站中使用按钮.因此,我想要一个按钮来调用相册的开头以选择要上传的图像.

What I want to do instead of using a button from the app's interface I wan to use a button within a website in a webview. So I want a button to call the opening of the photo album to select a image to upload.

基本上,我需要一种让javascript函数在应用程序本身中调用动作的方法.

Basically I need a way for a javascript function to call a action in the app itself.

我该怎么做?

推荐答案

您可以使用自定义链接,然后可以在UIWebViewDelegate方法中检测到该链接.

You could just use a custom link, which you can then detect in the UIWebViewDelegate method.

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

    if (navigationType == UIWebViewNavigationTypeLinkClicked) {
        NSString *rawURL = [[request URL] absoluteString];
        if([rawURL isEqualToString:@"callImageLib://"]) {
                [self methodeForImageLib];
        }     
        return NO;
    }

    return YES;
}

这篇关于使用JavaScript从UIWebView进行调用操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆