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
4
votes
5 answers

How to get requesting UIWebView from inside of NSURLProtocol

My app uses subclassing of NSURLProtocol. There are several UIWebViews in the app and for specific algorithm implemented in NSURLProtocol I need to know which one of the UIWebViews sends the request. My understanding is that object returned by [self…
okonov
  • 198
  • 1
  • 1
  • 9
4
votes
1 answer

Handling redirects with custom NSURLProtocol and HTTP proxy

I have a custom URLProtocol where I want to redirect all traffic via a proxy server. My current working code looks like that: +(BOOL)canInitWithRequest:(NSURLRequest*)request { if ([NSURLProtocol propertyForKey:protocolKey inRequest:request]) …
Gilad Novik
  • 4,546
  • 4
  • 41
  • 58
4
votes
1 answer

NSURLSessionTask authentication challenge completionHandler and NSURLAuthenticationChallenge client

I am implementing a custom NSURLProtocol, and internally want to use NSURLSession with data tasks for internal networking instead of NSURLConnection. I have hit an interesting problem and wonder about the internal implementation of the challenge…
Léo Natan
  • 56,823
  • 9
  • 150
  • 195
4
votes
2 answers

Caching not working with custom NSURLProtocol

I am trying to make a subclass to NSURLProtocol. However, I am noticing that I seem to lose caching functionality when I register my subclass, even though it shouldn't do anything. For example, if I do [NSURLConnection sendSynchronousRequest...]…
ahb
  • 160
  • 2
  • 9
4
votes
0 answers

Can a custom NSURLProtocol be accessed from external code?

My app registers a NSURLProtocol subclass that intercepts one specific URL. The protocol replies to requests with a secret key. @implementation PrivateURLProtocol // ignore everything besides keyURL + (BOOL)canInitWithRequest:(NSURLRequest…
Neal Ehardt
  • 10,334
  • 9
  • 41
  • 51
4
votes
1 answer

CFNetwork internal error

I'm creating my own NSURLProtocol with a caching system and I'm seeing this on the console: 4676: CFNetwork internal error (0xc01a:/SourceCache/CFNetwork_Sim/CFNetwork-609.1.4/Connection/URLConnectionClient.cpp:558 Any idea what is causing…
cynistersix
  • 1,215
  • 1
  • 16
  • 30
4
votes
1 answer

Using AVURLAsset on a custom NSURLProtocol

I have written a custom NSURLProtocol (called "memory:") that allows me to fetch stored NSData items from a NSDictionary based on a name. For example, this code registers the NSURLProtocol class and adds some data: [VPMemoryURLProtocol…
Cthutu
  • 8,713
  • 7
  • 33
  • 49
3
votes
0 answers

Implement URLProtocol but respect session configuration

I want to intercept all network calls (request and response) in an application, so I'm implementing a concrete URLProtocol subclass. Most online examples simply create a new URLSession with the default configuration for each task. Which means that…
3
votes
0 answers

what's the consequence of registering the same NSURLProtocol more than once?

I'm building a component that supports the enabling / disabling of a feature that requires an NSURLProtocol. in the isEnabled setter I do: - (void)setIsEnabled:(BOOL)isEnabled { _isEnabled = isEnabled; if (isEnabled) { [NSURLProtocol…
Noam
  • 620
  • 7
  • 13
3
votes
3 answers

Passing data to objective c with POST rather than GET

I have been using the url intercept method to pass data from javascript to objective C by passing the data as url encoded parameters and using NSURLProtocol to intercept the request however I am now wanting to send larger amounts of data like say…
yodaisgreen
  • 2,310
  • 3
  • 22
  • 27
3
votes
1 answer

Get list of all currently registered NSURLProtocol subclasses?

What is the correct way to determine all NSURLProtocol subclasses that are currently registered in an app? In the docs, I only see methods for + (BOOL)registerClass:(Class)protocolClass and + (void)unregisterClass:(Class)protocolClass. Does anyone…
72A12F4E
  • 1,744
  • 1
  • 14
  • 28
3
votes
1 answer

NSURLProtocol - startLoading not invoked

Since upgrading to iOS 9.1 my custom NSURLProtocol, won't invoke -(void)startLoading anymore. Has anyone else experienced this ? Everything worked fine on iOS 8 ... Code: @implementation RZCustomProtocol @dynamic request; +…
strangfeld
  • 1,067
  • 1
  • 9
  • 16
3
votes
2 answers

UIWebView/NSURLProtocol - placeholder for non-reachable external assets when offline

My app is an eReader for viewing books on iPhone/iPad. User has an option of downloading the book which we save on device as an .epub file (zipped content) - this enables the book viewing when offline. The page content is in html. Some assets, like…
rich
  • 461
  • 2
  • 5
  • 13
3
votes
1 answer

Custom URL protocol in Windows to serve HTML content

This question addresses how to register a custom URL protocol to launch an application in response to a link, but I want my handler to serve dynamic content. Essentially, I'm looking to create a web application that runs on the user's machine…
Tony the Pony
  • 40,327
  • 71
  • 187
  • 281
3
votes
3 answers

UIWebView not loading contents of redirected page when using custom NSURLProtocol

I have a UIWebView and a custom NSURLProtocol class registered to proxy HTTP requests. I have a problem loading github.com on it. If I browse to https://github.com then it loads the page and its contents just fine. However, if I browse to…
run2thesun
  • 358
  • 5
  • 12
1 2
3
9 10