Questions tagged [nsurlprotocol]

NSURLProtocol is an abstract class that provides the basic structure for performing protocol-specific loading of URL data.

NSURLProtocol is available in iOS 2.0 and later with iOS and available in OS X v10.2 with Safari 1.0 installed ,available in OS X v10.2.7 and later with OSX.

An NSURLProtocol object handles the loading of protocol-specific URL data. The NSURLProtocol class itself is an abstract class that provides the infrastructure for processing URLs with a specific URL scheme. You create subclasses for any custom protocols or URL schemes that your app supports.

Apps never need to instantiate an NSURLProtocol subclass directly. When a download starts, the system creates the appropriate protocol object to handle the corresponding URL request. All you have to do is define your protocol class and call the registerClass: class method during your app’s launch time so that the system is aware of your protocol.

Source : NSURLProtocol Class Reference

NOTE

You cannot use this class to define custom URL schemes and protocols in watchOS 2 and later.
144 questions
56
votes
4 answers

NSURLConnection delegate methods are not called

I am trying to create a simple NSURLConnection to communicate with a server using a GET request. Connection works well, but delegates methods of NSURLConnection are never called.. Here is what am doing: NSString *post = [NSString…
Manish Ahuja
  • 4,459
  • 3
  • 25
  • 35
47
votes
5 answers

iOS WebView remote html with local image files

Similar questions have been asked before, but I could never find a solution. Here is my situation - my UIWebView loads a remote html page. The images used in the web pages are known at build time. In order to make the page load faster, I want to…
CM Subram
  • 473
  • 1
  • 5
  • 4
18
votes
4 answers

How can i monitor requests on WKWebview?

How can i monitor requests on WKWebview? I'v tried using NSURLprotocol (canInitWithRequest) but it won't monitor ajax requests (XHR), only navigation requests(document requests)
Benzi Heler
  • 1,088
  • 1
  • 10
  • 18
14
votes
4 answers

Custom NSURLProtocol with NSURLSession

I'm trying to implement this tutorial which implements a custom NSURLProtocol with NSURLConnection. https://www.raywenderlich.com/76735/using-nsurlprotocol-swift It works as expected, but now that NSURLConnection is deprecated in iOS9, I'm trying to…
kupilot
  • 465
  • 1
  • 3
  • 13
14
votes
2 answers

How to mock AJAX call with NSURLProtocol?

I have UIWebview that makes AJAX calls to external services. When offline i need to catch theses requests and return local json. I implemented a NSURLProtocol and i manage to catch the AJAX request, the problem is jquery always return a 0 error code…
vdaubry
  • 11,071
  • 7
  • 52
  • 76
11
votes
3 answers

How to set statusCode in NSURLResponse

I override NSURLProtocol and need to return HTTP response with specific statusCode. NSHTTPURLResponse does not have statusCode setter, so I tried to override it with: @interface MyHTTPURLResponse : NSHTTPURLResponse {} @implementation…
okonov
  • 188
  • 1
  • 1
  • 9
11
votes
2 answers

UIWebView slow loading using NSUrlProtocol Xamarin.Forms

I'm working on an iOS application using Xamarin.Forms. This application is using UIWebView controller that shows a web application that is hosting on my server. Each time that I make a request I have to send a custom header in order to identify that…
avmauricio
  • 1,008
  • 1
  • 7
  • 19
10
votes
1 answer

Should a custom NSURLProtocol follow redirects itself, or let its client worry about that?

The NSURLProtocolClient protocol includes a method, -URLProtocol:wasRedirectedToRequest:redirectResponse:, which instances of NSURLProtocol subclasses are supposed to use to tell an URL protocol client that the request was redirected. However, I'm…
Caleb
  • 120,112
  • 19
  • 171
  • 259
9
votes
2 answers

Using a custom NSURLProtocol with UIWebView and POST requests

In my iOS app, I'm using a UIWebView and a custom protocol (with my own NSURLProtocol implementation). I've been fairly careful about making sure that whenever I load a url, I load something like this into my…
bcholmes
  • 894
  • 7
  • 22
9
votes
1 answer

NSURLProtocol canInitWithRequest: called multiple times

Our app has a lot of web views in it and I recently added a NSURLProtocol to interceptor some of the requests from them. I've noticed that some of the web views are calling the +[NSURLPRotocol canInitWithRequest:] method multiple times with what…
drekka
  • 18,723
  • 12
  • 67
  • 112
8
votes
4 answers

How to play movie with a URL using a custom NSURLProtocol?

As you know,play a movie with MPMoviePlayerController object using [[MPMoviePlayerController alloc] initWithContentURL: aURL]; now ,i want to achieve a custom NSURLProtocol in which i will decrypt a movie source that had be encrypt by …
ben
  • 1,020
  • 1
  • 15
  • 27
8
votes
2 answers

iOS Crash with SIGABRT in CFNetwork

I use custom url protocol in my app by extending NSURLProtocol. It works fine most of the time but I see the following crash being reported via crashlytics. I'm unable to reproduce this myself. The thing that worries me most is, I don't see my app…
Ravi
  • 521
  • 8
  • 21
8
votes
2 answers

NSURLProtocol - startLoading not called after canInitWithRequest returns YES for page resource

I'm having an issue where a video resource in my UIWebView is not loading. This is only an issue on an actual device- everything works perfectly on the simulator. Note: I've already checked this and the issue there has to do with loading the same…
Stonz2
  • 6,072
  • 4
  • 41
  • 60
7
votes
1 answer

Custom NSURLProtocol slower after switching NSURLConnection to NSURLSession

I have a custom NSURLProtocol ("UrlProtocol") written to intercept requests from a UIWebView when navigating to specific websites, and apply an extra HTTP header before being sent. I followed…
Chicowitz
  • 5,241
  • 5
  • 26
  • 36
7
votes
3 answers

Using NSURLProtocol with NSURLSession

My application uses NSURLConnection to communicate with server. We use https for communication. In order to handle authentication from all request in one place i used NSURLProtocol and handled authentication in delegates in that class. Now I have…
vishnuvarthan
  • 482
  • 1
  • 6
  • 22
1
2 3
9 10