JLTChiu
JLTChiu

Reputation: 1023

Can we limit the domain we visit from ios in-app browser?

I am developing an ios app, and I wish to use the in-app browser. But I wish to limit the domain visited with in-app browser. (Ex: limited to the .com website only.) Is there a way to implement this restriction?

Upvotes: 1

Views: 265

Answers (2)

Jim
Jim

Reputation: 73936

If you need to know if you can do something with a web view, start by looking at the documentation - UIWebView class reference.

From there, you can see that it has a delegate property that is sent messages when content is loading. So next, you look at the documentation for the UIWebViewDelegate protocol.

From there, you can see that the delegate is sent a webView:shouldStartLoadWithRequest:navigationType: message before the web view loads content. Looking at the documentation for that method tells you that you need simply return NO from that method to cancel loading content.

So provide a delegate for the web view that implements that method which returns NO when you see a URL you don't like.

In future, please check the documentation before asking on Stack Overflow.

Upvotes: 1

A-Live
A-Live

Reputation: 8944

Sent before a web view begins loading a frame.

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

Parameters

webView The web view that is about to load a new frame. request The content location. navigationType The type of user action that started the load request.

Return Value

YES if the web view should begin** loading content; otherwise, NO .

You should always read the documentation

Upvotes: 2

Related Questions