开发者

Restrict UIWebview to certain pages

I am trying to create a simple ipad app with a UIWebview that displays a form that a customer can fill in.. what i want to do is restrict the app so that it only allows the user to navigate to certain addresses.. (i.e. either something that allows the user to go to a specific address.. OR something that checks for specific keywords and allows/blocks them as appropriate..)

Could someone please show me how its done..

NB: its basically a googledocs form and i dont want to let the user navigate away from it.. (the user could easily click away and go elsewhere)

Thank you开发者_如何学C for reading :)


In the class that is your UIWebViewDelegate you can use something like this:

-(BOOL) webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSURL *url = request.URL;
    NSString *urlString = url.absoluteString;

    //Check for your own url. You can use more advanced checking techniques of course :)
    NSRange range = [urlString rangeOfString:@"http://www.yourUrl.com"];
    if (range.location != NSNotFound) 
        return YES;
    else
        return NO;
}


You can use the delegate method

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

to determine whether the UIWebView can load a given web page. Although that would mean knowing exactly which pages are allowed (if there are many this might not be convenient).


Use UIWebViewDelegate method webView:shouldStartLoadWithRequest:navigationType:

Then check what is the URL that the UIWebView tires to load, and act consequently.

UIWebViewDelegate Reference

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜