2014-05-17 33 views
2

我想獲取UIWebView中的所有請求列表(圖像/視頻/ CSS)。 我使podclass NSURLCache,它的工作,但我碰到。如何獲取UIWebView中的所有請求?

代碼:

#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

我通過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; 
} 
相關問題