0

im developing an app, which requires to load some menu's and presentations(pdf, flash etc.) menu items are loaded from database and each contains ID and Text. Menu items looks like below:

Crocin Combiflame

above menu items are hyper links, clicking them will open up presentations on the same page.

i need to call a xcode method in this scenario which can query database (located in document folder in app) and return presentation name and some other details.

i got two problems here

1) i came across

**– webView:shouldStartLoadWithRequest:navigationType:**

but this method returns BOOL and i want to return Presentation with other information

2) no idea how can i load presentation (inside Resources Folder of my app ) via javascript on the same page.

Any suggestions will b greatly appreciated. Thanks in advance.

2 Answers 2

1

You can do pretty much what you need in webView:shouldStartLoadWithRequest:navigationType.

  1. If you return NO from it, then the web view will not load the current request; this will make your app free of doing whatever it needs:

  2. you can then either load a different request in the same web view (say an HTML string that embeds the presentation resource),

  3. or, you can send a message to some controller of yours to run a different workflow altogether (display a different kind of view or whatever).

EDIT:

elaborating more option 2:

  1. say that you have a view controller which embed the UIWebView and also acts as delegate for it;

  2. you could define a method in the view controller which gets and HTML string and loads it into the web view, like this:

    - (void)loadContentInWebView:(NSString*)content {
         [_webView loadHTMLString:content  baseURL:nil];
    }
    
  3. now, in webView:shouldStartLoadWithRequest:navigationType, you could do something like this:

    - (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
            if ([[[request URL] absoluteString] isEqual:WHATEVER]) {
                 [self loadContentInWebView:HERE_THE_HTML];
                 return NO;
        }
        return YES;
    }
    

What you should define here is:

 ([[[request URL] absoluteString] isEqual:WHATEVER])

i.e., the logics to understand when the user touched some link that should make a presentation loaded;

and:

  [self loadContentInWebView:HERE_THE_HTML];

i.e., define in some way the HTML content that you want to use so to have the presentation displayed.

Sign up to request clarification or add additional context in comments.

2 Comments

you can then either load a different request in the same web view (say an HTML string that embeds the presentation resource) This is what i want to do. Bt not clear how!!! i have <embed> tag inside my webview (which is displaying HTML5 page) but how can i change its Src attribute in webView:shouldStartLoadWithRequest:navigationType method ?? any link resource where same thing has been done...
Please, see my edit... you do not change the src attribute, you return NO (initial request is aborted) and create a new one.
0

i got a work around..although it is not a good practice:

in model: This method gets called whenever a request comes for this webview even when the page loads in webview

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    // check the request, if it's ajax callback, just return NO; other wise YES;


//    NSURLRequest *request = [self request];
    NSURL *url = [request URL];

    NSString *file = [url lastPathComponent];
    if ([file isEqualToString:@"Presentation.html"] == YES) {
        return YES;
    }

    if ([file isEqualToString:@"ajaxcallback.htm"] == YES) {
        // that means the ajax call is done, so you can call this 
        NSString *result = [web stringByEvaluatingJavaScriptFromString:@"getResponse();"];

        // don't forget to stop loading this fake page
        return NO;
    }
}

and in javascript:

   function sendRequestToApp(){
        window.location="http://www.domain.com/ajaxcallback.htm";
    }

    function getResponse(src){
        alert("response");
        document.getElementById("sample").src=src;
    }

Comments

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.