开发者

iPhone: How to prevent App (or UIWebView) from accessing the network/web

one of the viewControllers in my iPhone App has a UIWebView. Whenever this viewController gets loaded, I would like to prevent my App from being able to access the web (regardles开发者_运维知识库s if an actual connection is available or not).

Background: What I am trying to do, is to ensure, that users with a limited data plan won't be "risking" to go beyond their limited when working with my App.

My App loads user specific html pages into a UIWebView. This particular viewController is kind of a preview - but it should not have web access.

So I either would like to prevent the UIWebView from accessing the web or be able to turn on/off web access for my entire App.

Any "App-store-save" ideas or recommendations would be greatly appreciated.

Thank you and

Best Regards,

Ralph

Edited on March 1st 2011:

Included more info:

It appears that the answer below from hotpaw2 (= using shouldStartWithLoadRequest) does unfortunately not provide a solution.

To give an example, I tested it by loading the follwing html into the UIWebView. The BaseURL is set correctly so that the local files can be accessed. As expected, shouldStartLoadWithRequest gets only called once for the initial load of the html.

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Test example</title>
</head>
<body>
<img src="image-On-Device.jpg" alt=""><br>
<img src="http://www.aWebsite.xx/anOnlineImage.jpg" alt=""><br>
<img src="image-On-Device.jpg" alt=""><br>
<img src="http://www.aWebsite.xx/anOnlineImage.jpg" alt=""><br>
</body>
</html>

This example will cause the device to access the web to fetch: "anOnlineImage.jpg".

Note: images are only one example of resources that might be requested online.

Hence, how can I prevent any type of webaccess - without having to modify the entire html?


Use the UIWebView webView:shouldStartLoadWithRequest:navigationType: delegate to inspect and return NO for any UIWebView attempts to access URLs other than those on your permitted list.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜