我想在UIWebView中获取所有请求列表(image / video / css)。 我制作了podclass NSURLCache ,它正在运行,但是我崩溃了。
代码:
#import <Foundation/Foundation.h>
@interface CacheProxy : NSURLCache
@end
#import "CacheProxy.h"
@implementation CacheProxy
- (NSCachedURLResponse*)cachedResponseForRequest:(NSURLRequest*)request
{
NSLog(@"url %@", request.URL);
return [super cachedResponseForRequest:request];
}
@end
初始化:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
CacheProxy *cache = [[CacheProxy alloc] initWithMemoryCapacity:100 * 1024 * 1024
diskCapacity:0
diskPath:nil];
[NSURLCache setSharedURLCache:cache];
}
崩溃:
CFNetwork`__CFURLCache::SetMemoryLimit(long, long):
答案 0 :(得分:0)
尝试优化NSURLCache:
http://twobitlabs.com/2012/01/ios-ipad-iphone-nsurlcache-uiwebview-memory-utilization/
答案 1 :(得分:0)
我通过NSURLProtocol解决了这个问题(http://www.raywenderlich.com/59982/nsurlprotocol-tutorial - 很好的教程)
#import <Foundation/Foundation.h>
@interface MyURLProtocol : NSURLProtocol
@end
#import "MyURLProtocol.h"
@implementation MyURLProtocol
+ (BOOL)canInitWithRequest:(NSURLRequest *)request
{
static NSUInteger requestCount = 0;
NSLog(@"Request #%u: URL = %@", requestCount++, request.URL.absoluteString);
return NO;
}