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
1
vote
0 answers

IOS Live streaming

Problem: I need to download mp4 video from media server and simultaneously feed the localhost httpserver (GCDWebServer) to enable video streaming. What have i tried so far: I am able to download a video file from media server and then provide the…
blganesh101
  • 3,647
  • 1
  • 24
  • 44
1
vote
2 answers

iOS: How to trap all NSURLRequests and NSURLResponses?

I want to log all the NSURLRequests which are initiated from within my app and response for those requests. I wrote a custom NSURLProtocol to achieve this. I was able to trap all the request but not the response. In canInitWithRequest method I can…
dev gr
  • 2,409
  • 1
  • 21
  • 33
1
vote
2 answers

NSURLProtocol and relative paths

I implemented a custom NSURLProtocol that allows me to use a static zipped version of a website as a target for a webView. It opens the zip on the go and load the required data. But the issue is that NSURLProtocol seems not to behave properly with…
Nerkatel
  • 1,805
  • 16
  • 25
1
vote
0 answers

NSURLProtocol doesn't get complete NSURLRequest

Problem: I have my subclass of NSURLProtocol, but the NSURLRequest returned by +canonicalRequestForRequest: or the request returned by -connection:willSendRequest:redirectResponse: are never passed to my URL protocol instance. Details: In my…
Roberto
  • 3,487
  • 1
  • 22
  • 24
1
vote
1 answer

How can I verify method calls to an NSURLProtocol mock using OCMock or OCMockito?

I would like to test a method which makes a GET request. Here's a contrived example: - (void)GET:(NSString *)URLString; Rather than worry about the implementation details of this method (e.g. mocking, setting expectations, and then verifying a…
Paul Young
  • 1,489
  • 1
  • 15
  • 34
1
vote
1 answer

Custom URL scheme as adapter on existing URL schemes

Is there a clean and spec-conformant way to define a custom URL scheme that acts as an adapter on the resource returned by another URL? I have already defined a custom URL protocol which returns a decrypted representation of a local file. So, for…
algal
  • 27,584
  • 13
  • 78
  • 80
1
vote
2 answers

how to make NSURL point to local dir?

reading Adium code today, found an interesting usage of NSURL: NSURL *baseURL = [NSURL URLWithString:[NSString stringWithFormat:@"adium://%@/adium", [messageStyle.bundle bundleIdentifier]]]; [[webView mainFrame] loadHTMLString:[messageStyle…
buaacss
  • 757
  • 6
  • 10
1
vote
1 answer

how can I deep-copy an NSMutableURLRequest?

Apple's iOS documentation on NSMutableURLRequest says: NSURLConnection makes a deep copy of each NSMutableURLRequest object passed to one of its initializers. How is this implemented? I don't see any documented way of performing deep copy of…
noamtm
  • 12,435
  • 15
  • 71
  • 107
1
vote
1 answer

CDVURLProtocol - startLoading method not executed when ajax calls are triggered

I'm trying to catch outgoing ajax calls in order to change the request by adding client certificate to it. It seems that it can be done by subclassing NSURLProtocol. In Phonegap there is already a subclass called CDVURLProtocol. The…
ridan
  • 858
  • 3
  • 11
  • 24
1
vote
1 answer

Is there a way to capture all NSURLRequests while loading a html-page?

To be specific: If I want download a html-page, there are many requests to image, music, js, etc, which I cannot handle by UIWebView delegates. To be more specific: I'm interested in handling of ajax-requests! I have tried to implement ajax-handler…
bezigon
  • 518
  • 7
  • 17
1
vote
1 answer

Loading resources from relative paths through NSURLProtocol subclass

I have an NSURLProtocol registered for a UIWebView-based app, set up to respond to file scheme requests. In the web view, I load images, CSS, JS etc. and all that's all working fine; the problem comes when I try to reference an image in a CSS file…
0
votes
1 answer

WKWebView decidePolicyForNavigationAction for html page resources

I have a need to monitor all failed requests from a given web page loaded in WKWebKit. For this, I implemented a simple controller with WKWebView on it and also conformed that controller to WKNavigationDelegate: - (void)viewDidLoad { [super…
Mando
  • 11,414
  • 17
  • 86
  • 167
0
votes
1 answer

A custom NSURLProtocol doesn't invoke canInitWithRequest:

I've implemented a subclass of NSURLProtocol. I need it to mock URL responses for a unit test. I've registered my class in the setUp method of the unit test. - (void)setUp { [NSURLProtocol registerClass:[RDMockResponseURLProtocol class]]; …
Dmytro Skorokhod
  • 424
  • 8
  • 17
0
votes
1 answer

Capture POST parameters in custom NSURLProtocol

I have an NSURLProtocol listening to POST requests on a UIWebView. I try to capture the POST parameters and first read here that httpBody is always nil as body data objects are converted into streaming-style bodies. Then I use the following…
romain64
  • 89
  • 9
0
votes
1 answer

Subclassing URLProtectionSpace

Aim: Test SSL pinning by using URLProtocol. Problem: Cannot subclass URLProtectionSpace in the expected manner. The server trust property is never called and the alamofire auth callback only receives a URLProtectionSpace class type instead of my…
Fawkes
  • 3,831
  • 3
  • 22
  • 37