0

How to differentiate a NSURLRequest between UIWebView and NSURLConnection in NSURLProtocol or NSURLCache?

I want to monitor a UIWebView's request without NSURLConnection, how to do?

The UIWebView's content has resource: js, image, href.

How to differentiate the NSURLRequest from this resource and common NSURLConnection?

thanks.

sKhan
  • 9,694
  • 16
  • 55
  • 53
fyxrhyry
  • 135
  • 1
  • 8

1 Answers1

0

look at the url you get from the request that is passed to the delegates

NSURL *urlRequest = ((NSHTTPURLRequest*)request).URL;

if you are inside a NSURLConnectionDelegate, this will get the request. If you are not, forget this line ;)

NSURLRequest *request = connection.originalRequest; 
Daij-Djan
  • 49,552
  • 17
  • 113
  • 135
  • Sorry, I want to in the NSURLProtocol's method + (BOOL)canInitWithRequest:(NSURLRequest *)request, judge the request whether is from a UIWebView or NSURLConnection. – fyxrhyry Mar 17 '16 at 08:54