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
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,759
  • 5
  • 32
  • 38
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
  • 492
  • 1
  • 6
  • 23
7
votes
2 answers

Map Custom URL protocol to HTTP (using NSURLProtocol?)

I have an application using a WebKit WebView and I'd like to map URL's that are loaded in this WebView with a custom URL protocol to a different HTTP URL. For example, say I am loading: custom://path/to/resource I would like to internally actually…
7
votes
3 answers

iOS - Use AFNetworking with custom NSURLProtocol class

I have a custom NSURLProtocol class that I have implemented with the help of this tutorial. My implementations are pretty much the same as in the tutorial, aside from the names, data model, etc... Essentially, I am trying to send a HTTP request, but…
orenk86
  • 720
  • 9
  • 24
6
votes
2 answers

NSURLProtocol and post upload progress

I am using a subclass of NSURLProtocol to intercept all HTTP calls and modify the user agent as well as add a other http headers required by my server. -(id)initWithRequest:(NSURLRequest *)request cachedResponse:(NSCachedURLResponse…
terrinecold
  • 231
  • 1
  • 9
6
votes
0 answers

How to get current ts file from avplayer

I'm trying to figure out how to get current ts file from the avplayer. I tried subclassing NSURLProtocol, but that doesn't show the url from the avplayeritem. Thanks.
ordinaryman09
  • 2,761
  • 4
  • 26
  • 32
6
votes
1 answer

What is the better way to encrypt NSURLCache?

I want to encrypt/decrypt all cached data from a NSURLSession using AES256. I'm new using Alamofire but I think it is possible to do it without involving the library itself. I don't know exactly what is the most seamless way to encrypt the data…
emenegro
  • 6,901
  • 10
  • 45
  • 68
6
votes
1 answer

Is there a way to use NSURLProtocol in a NSURLSession with custom config?

I have a NSURLSession that runs in a background queue. I'm adding my NSURLProtocol subclass to the NSURLsessionConfiguration.protocolClases but the override class func canInitWithRequest(request: NSURLRequest) -> Bool never gets called. This is how…
Andres
  • 11,439
  • 12
  • 48
  • 87
6
votes
1 answer

NSURLProtocol fails for video request

I'm having some issues with video requests handled through a special protocol scheme in a NSURLProtocol subclass. Every other resource (images/text) are getting handled correctly, however, when a video request is sent, I only get a call to…
Meda
  • 2,776
  • 4
  • 20
  • 31
6
votes
4 answers

iOS: passing custom NSURL to NSURLProtocol

I need to pass some extra informations along with UIWebView loadRequest: so that it reaches my implementation of NSURLProtocol. The information cannot be bound to NSURLRequest because the information must be retained with NSURLRequest…
Pavel Zdenek
  • 7,146
  • 1
  • 23
  • 38
6
votes
0 answers

iOS: HTTP Basic/Digest Auth with a UIWebView

Overview I'm working on a SAML login (single sign-on, similar to openID) solution for an iOS app that involves showing a view controller with a UIWebView and I'm running into a timing and/or timeout issue when handling HTTP basic/digest auth in the…
5
votes
2 answers

How can I pass a dependancy to a URLProtocol subclass?

I have been working on an interceptor for adding auth headers to network requests in my app. final class AuthInterceptor: URLProtocol { private var token: String = "my.access.token" private var dataTask: URLSessionTask? private…
Harry Blue
  • 4,202
  • 10
  • 39
  • 78
5
votes
0 answers

Return custom NSURLResponse class

I try to return an object of a subclass of NSURLResponse in my custom NSURLProtocol, but it seems the returned response is always exchanged by a normal NSURLResponse. This is the part of the NSURLProtocol where I return my custom…
cemonds
  • 225
  • 1
  • 9
5
votes
1 answer

Possible to play video using a subclass of NSURLProtocol, using either MPMovieController or AVFoundation?

I'm currently trying to play a video to a URL that has the custom scheme defined in a custom NSURLProtocol subclass. Initially I was using MPMoviePlayerController in an attempt to accomplish this, but after running into problems and checking stack…
Taz
  • 1,203
  • 1
  • 11
  • 21
5
votes
2 answers

Correlate NSURLRequest with UIWebView

In iOS, I'd like to be able to associate an NSURLRequest--any NSURLRequest, whether a navigation request or image or stylesheet request--with the UIWebView that sent it. This seems to call for the implementation of an NSURLProtocol subclass to…
KevinH
  • 2,034
  • 1
  • 12
  • 12
1
2
3
9 10