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

how to intercept HTTP request by NSURLProtocol at airplane mode (offline, ios)

We're trying to cache some H5 pages in device and have used NSURLProtocol to intercept HTTP requests. At normal network type (wifi / 4G / 3G / 2G) it works well, but failed at airplane mode (or close cell + wifi). Error occured: -1009. Any ideas to…
1
vote
1 answer

Register NSURLProtocol (URLProtocol) class for use with external app?

I want to use a custom NSURLProtocol class to serve static data for testing and I have done this implementing the protocol in the application itself and registering it to the NSURLSessionConfiguration.protocolClasses. I want to move the protocol…
1
vote
1 answer

NSURLSession sessionWithConfiguration did not call in custom NSURLProtocol's method canInitWithRequest

I have a subclass of NSURLProtocol, The NSURLConnection works well. And [NSURLSession sharedSession] works well too. But, [NSURLSession sessionWithConfiguration:configuration] not work, I called the [NSURLProtocol…
fyxrhyry
  • 135
  • 1
  • 8
1
vote
1 answer

HTTPMaximumConnectionsPerHost,timeoutIntervalForRequest not affecting with defaultSession when used in iOS custom protocol

I am using custom protocol where I create NSURLSession with defaultConfiguration. Here is my code - ` NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration]; config.timeoutIntervalForRequest =…
1
vote
1 answer

0_ os_lock_corruption_abort in NSURLProtocol

I've built a custom NSURLProtocol which is used by a WebView whilst it browses. But at seemingly random times (between a 20 seconds or a few minutes into browsing) I am getting an EXC_BREAKPOINT and the app stops running in my NSURLProtocol. The…
Sam Heather
  • 1,493
  • 3
  • 19
  • 42
1
vote
1 answer

WebView can't handle response when using a custom NSURLProtocol

I'm using a custom NSURLProtocol in order to be able to save the username and password from a form that is loaded in a webView and automatically log the user in. My issue is that I can get the data, but I can't complete the action to login the user…
Tchelow
  • 593
  • 4
  • 15
1
vote
1 answer

What exactly +[NSURLProtocol setProperty:forKey:inRequest:] does

NSURLProtocol defines following methods: /*! @method propertyForKey:inRequest: @abstract Returns the property in the given request previously stored with the given key. @discussion The purpose of this method is to provide an…
Borys Verebskyi
  • 4,160
  • 6
  • 28
  • 42
1
vote
1 answer

NSURLSession and NSURLProtocol issue on iOS 8

I have an app working just fine on iOS 9 with a Custom NSURLProtocol implemented with NSURLSession. All the requests executed by the client are done with NSURLSession as well and each sessionConfiguration is registering to the protocol before…
iOSAddicted
  • 389
  • 1
  • 17
1
vote
2 answers

Placeholder image for slow downloads with NSURLProtocol for a UIWebView

I needed to load images from the iCloud Document Storage in my WebView I have solved this problem with my own implementation of the NSURLProtocol. My problem is, that the download is very slow and the User doesn't see any Indicator in the web page…
ChaosSpeeder
  • 3,468
  • 5
  • 30
  • 38
1
vote
2 answers

Use local resources in WKWebview

How do I make WKWebview use local .js, .css and/or local image files, in place of remote files, in order to make the web page load faster. Also, I noticed NSURLProtocol methods (when implemented through register class) do not get called when…
Krishnan Sriram
  • 5,037
  • 5
  • 21
  • 31
1
vote
2 answers

NSURLProtocol - handle https request

This is canInitWithRequest in NSURLProtocol: + (BOOL)canInitWithRequest:(NSURLRequest *)request { // only handle http requests we haven't marked with our header. if ([[[request URL] scheme] isEqualToString:@"http"] && ([request…
Nitish
  • 13,845
  • 28
  • 135
  • 263
1
vote
0 answers

ios Custom Player instead of default MPMoviePlayerController inside UIWebView

I have a custom player built using AVFoundation libraries (contains some custom streaming logic and controls). The player is not using MPMoviePlayerController classes. Inside UIWebView, there is some logic (might be the content-type) which detects…
1
vote
0 answers

use NSURLProtocol and NSURLSession to do do proxy request,when My proxy server required username and password, it returns warning

I use NSURLProtocol and NSURLSession to do do a webview proxy request, it works when My Proxy server is Anonymous, but, when My proxy server required username and password, it returns the following warning CFMachPortSetInvalidationCallBack() called…
Coly
  • 11
  • 4
1
vote
2 answers

NSURLProtocol isn't asked to load after YES response to canInitWithRequest

I'm registering an implementation of NSURLProtocol to do some custom handling of certain URL requests (I tag these requests by setting properties on them). These URL requests are coming from a UIWebView's load method. Create a UI web view (first…
Ben Flynn
  • 18,524
  • 20
  • 97
  • 142
1
vote
0 answers

NSURLProtocol + WebView = Not able to get Data of HTTP post

I have created a scaled down version of my own browser using WebView + NSURLProtocol. I took the sample code from following blog to get started. http://www.raywenderlich.com/59982/nsurlprotocol-tutorial ( To download the code, go to heading "Where…
iOSMonkey
  • 119
  • 1
  • 1
  • 9