URL filtering for UIWebView on the iPhone

限于喜欢 提交于 2020-01-24 19:45:46

问题


Can someone please shed some light on how I would get this to work: http://www.icab.de/blog/2009/08/18/url-filtering-with-uiwebview-on-the-iphone/

I tried making the "FilteredWebCache.h" and "FilteredWebCache.m" files in my project, but it said that "FilterManager.h" did not exist. What am I meant to do with those files?

This I put in viewDidLoad:

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *docDir = [paths objectAtIndex:0];
    NSString *path =  docDir; // the path to the cache file
    NSUInteger discCapacity = 10*1024*1024;
    NSUInteger memoryCapacity = 512*1024;

    FilteredWebCache *cache = [[FilteredWebCache alloc] initWithMemoryCapacity:memoryCapacity  diskCapacity:discCapacity diskPath:path];
    [NSURLCache setSharedURLCache:cache];
    [cache release];

回答1:


You need to write the FilterManager class yourself (FilterManager.m and FilterManager.h). That post says:

The code first checks if the URL should be blocked (the FilterManager class is doing all these checks, this class isn’t shown here).

The example code seems to call it FilterMgr instead of FilterManager, and it looks like you need to provide a shouldBlockURL: method that decides what gets blocked.

BOOL blockURL = [[FilterMgr sharedFilterMgr] shouldBlockURL:url];


来源:https://stackoverflow.com/questions/2604440/url-filtering-for-uiwebview-on-the-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!