I have my URLProtocol
implementation class.
In my app I have there is more than one UIViewController
that can do http requests (there is only one visible, but more actives).
There is a way to know what instance of viewcontroller (in my URLProtocol
implementation) is making the request?
Asked
Active
Viewed 70 times
0

Pol
- 948
- 1
- 8
- 19
-
Just make a method that accepts UIViewController? – Alexander M. Oct 24 '16 at 08:59
-
You better to use blocks, to receive callback from your requests, not delegate. – Mr.Fingers Oct 24 '16 at 09:02
-
Why not cut & paste some code that describes how you are generating your http requests and how you are implementing URLProtocol? – Michael Dautermann Oct 24 '16 at 09:03
-
The requests are made by a webview, for requests that I write there is no problem of course, because I know all of those. – Pol Oct 24 '16 at 09:07
-
What kind of webview is it? UIWebView or WKWebView or? – Michael Dautermann Oct 24 '16 at 09:55
-
UIWebView, with WKWebView we can't use URLProtocol – Pol Oct 24 '16 at 09:56
1 Answers
0
Set your view controller to be a delegate of your UIWebView (if you haven't done it already), then you can do something like this:
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
NSLog(@"url %@", [[request URL] absoluteString]);
// now you know which view controller made this request
//
// you could save this to a property in the view controller
// or to a table of view controllers/web views
return YES;
}
I'm basing my answer on what I found in this very related question.

Community
- 1
- 1

Michael Dautermann
- 88,797
- 17
- 166
- 215