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.
142 questions
57
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,509
  • 3
  • 28
  • 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
19
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,138
  • 1
  • 10
  • 18
15
votes
2 answers

How to intercept a WKWebView request to detect which local resource files (css, js, png, ...) load together with a HTML file?

I have a HTML file which contains local resource files such as css, js and png files inside its content. These local resource files are in zip format. My app use WKWebView to display this html file. I want to find a solution to intercept the web…
Tony Pham
  • 393
  • 1
  • 3
  • 9
15
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
  • 494
  • 1
  • 3
  • 15
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,369
  • 7
  • 54
  • 76
12
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
  • 198
  • 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
2 answers

Why is the HTTPBody of a request inside an NSURLProtocol Subclass always nil?

I have my NSURLProtocol MyGreatProtocol. I add it to the URL Loading system, NSURLProtocol.registerClass(MyGreatProtocol) I then start receiving events inside MyGreatProtocol during network sessions. Suppose I create the session after registering…
James Graham
  • 470
  • 2
  • 8
  • 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
  • 124,013
  • 19
  • 183
  • 272
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
  • 944
  • 1
  • 9
  • 23
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
  • 20,957
  • 14
  • 79
  • 135
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
  • 523
  • 8
  • 23
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,306
  • 4
  • 44
  • 64
1
2 3
9 10