Call action from UIWebView with JavaScript

北城余情 提交于 2019-12-25 03:58:06

问题


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

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.

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

How can I do this?


回答1:


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;
}



回答2:


If i understand it correctly you need to communicate iPHone Web application to call native iPhone application and visa versa. please check the following links.

http://blog.techno-barje.fr/post/2010/10/06/UIWebView-secrets-part3-How-to-properly-call-ObjectiveC-from-Javascript

http://iphoneincubator.com/blog/windows-views/how-to-inject-javascript-functions-into-a-uiwebview

hope these 2 link help to solve your issue.



来源:https://stackoverflow.com/questions/6422637/call-action-from-uiwebview-with-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!