D
D
deleted-mezhevikin2014-05-17 16:39:02
Objective-C
deleted-mezhevikin, 2014-05-17 16:39:02

How to get a list of all requests in a UIWebView?

I want to get a list of all requests from UIWebView, i.e. requests for images/css/js files.
I found a method: make a subclass of NSURLCache and in the cachedResponseForRequest method: monitor all requests, but the problem is that with large requests, such as video, I get an out-of-memory crash, clearing the cache by memorywarning does not help.
Are there other ways to intercept requests or how to subordinate this method?
The code:

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

Initialization in appdelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        CacheProxy *cache = [[CacheProxy alloc] initWithMemoryCapacity:100 * 1024 * 1024
                                      diskCapacity:0
                                          diskPath:nil];
 [NSURLCache setSharedURLCache:cache];
    }

Crash:
CFNetwork`__CFURLCache::SetMemoryLimit(long, long):

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
A
AlexKar, 2014-05-17
@deleted-mezhevikin

I think you should look into NSURLProtocol, by defining + (BOOL)canInitWithRequest:(NSURLRequest *)request you can dump everything you need.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question