0

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?

2 Answers 2

4

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;
}
Sign up to request clarification or add additional context in comments.

4 Comments

I can't seem to get shouldStartLoadWithRequest to trigger, I add - NSLog( @"Ytest" ); to the beginning to see if it would work, but it doesn't seem to intercept to change of location. I placed the code in AppDelegate.m with @synthesize webView; at the top.
Dot not place the code in the appdelegate but in the viewController the displays the webview. Then set the self.webView.delegate = self; in the viewDidLoad of the viewController.
My appdelegate's window is displaying the webview?
Then add a ViewController, this is a better way of spilliting op your code. Or se the delegate of the webiview to your appDelegate if you realy want to go that way. So where you create the webView use:self.webView.delegate = self
0

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.

1 Comment

Demo, here is another blob on the topic Javascript run in UIWebview, please refer to :creiapp.blogspot.hk/2013/04/uiwebview-javascript.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.