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
2
votes
1 answer

NSURLProtocol time out with AJAX

I use NSURLProtocol to add custom header to all requests going out of UIWebview. In this WebView on doing certain operation AJAX call is fired to display a message.This operation to show message uses AJAX, and always times out when i use…
Aditya Gaonkar
  • 660
  • 6
  • 13
2
votes
2 answers

NSURLProtocol. requestIsCacheEquivalent never called

I'm not sure what the deal is here, but the function: class func requestIsCacheEquivalent(a: NSURLRequest, toRequest b: NSURLRequest) -> Bool is never called within my NSURLProtocol subclass. I've even seen cases of the cache being used (verified…
fjlksahfob
  • 1,019
  • 3
  • 16
  • 27
2
votes
0 answers

problem with custom NSProtocol and caching on iPhone

My iPhone app embeds a UIWebView which loads html via a custom NSProtocol handler I have registered. My problem is that resources referenced in the returned html, which are also loaded via my custom protocol handler, are cached and never reloaded.…
TomSwift
  • 39,369
  • 12
  • 121
  • 149
2
votes
1 answer

Phonegap and MobileIron compatibility

I developed a PhoneGap application for iOS devices. For security reasons, I need to integrate a MobileIron product. In particular, I have to import MobileIron's AppConnectSDK for iOS into my Xcode project. I'm concerned thatNSURLProtocol subclass is…
Enrico C.
  • 19
  • 4
2
votes
3 answers

How to use NSURLCache to cache content served by an NSURLProtocol

I've written an NSURLProtocol that will check outbound http requests against a plist of URL to local path mappings and serve up the local content instead, and then cache it using NSURLCache: - (void)startLoading { //Could this be why my…
Scott McCoy
  • 308
  • 2
  • 13
2
votes
0 answers

iOS - How to add a custom header field to every request made by my UIWebView

I want to add a custom header field to every request made by my UIWebView. First I tried to do this in the "shouldStartLoadWithRequest" method in my controller, but this only works for the first request made - all subsequent requests are not handled…
guilhermekrz
  • 68
  • 11
2
votes
0 answers

Using NSOutputStream outputStreamWithURL with a custom URLprotocol

I'm writing a custom URL protocol (subclass of NSURLProtocol) to deal with local files that need a special way of reading and writing. No problem when reading: I can successfully create an URL like -for example- "my-funny-file-protocol://...." and…
roberto.buratti
  • 2,487
  • 1
  • 16
  • 10
2
votes
1 answer

Using NSURLProtocol to implement play while downloading for AVPlayer on iOS

I'm trying to play a mp4 video on my server and I'd like to cache this video to disk simultaneously. I know that I can just use 2 requests to do this, one for download another one created by AVPlayer to play the video, but this will waste the…
Jay Zhao
  • 946
  • 10
  • 24
1
vote
1 answer

Custom NSURLProtocol not used in second webview

I've subclassed NSURLProtocoland registered it in didFinishLaunchingWithOptions with this code: + (void) registerProtocol { static BOOL registered = NO; if (!registered) { [NSURLProtocol registerClass:[MyURLProtocol class]]; …
user826955
  • 3,137
  • 2
  • 30
  • 71
1
vote
1 answer

AVPlayer URL custom loading for HTTPS

I'm trying to use AVPlayer with custom URL loading (a custom NSURLProtocol subclass). But it seems [NSURLProtocol registerClass] does not work with AVPlayer in real device (see this thread). Now I'm trying to use AVAssetResourceLoaderDelegate to do…
user1783732
  • 1,599
  • 5
  • 22
  • 44
1
vote
0 answers

NSURLProtocol registerClass works for iOS simulator but not actual device

I am calling [NSURLProtocol registerClass] to use a custom protocol (Chromium Cronet) when playing a video using AVPlayer. (The register is done at here: ) It works well on iOS simulator (Xcode 11.3) but when runs on an actual device (iPhone SE,…
user1783732
  • 1,599
  • 5
  • 22
  • 44
1
vote
0 answers

Comparison between NSMutableURLRequest and URLRequest in URLProtocol implememtation

The NSURLProtocol documentation says it is possible to set a key-value and associate it with a request. The documentation calls it "tagging a request". class func property(forKey: String, in: URLRequest) Returns the property associated with the…
RickiG
  • 11,380
  • 13
  • 81
  • 120
1
vote
2 answers

URLProtocol doesn't get initialized

I am implementing an URLProtocol in an app. import Cocoa class MyURLProtocol: URLProtocol { override init(request: URLRequest, cachedResponse: CachedURLResponse?, client: URLProtocolClient?) { super.init(request: request,…
Sandro
  • 84
  • 5
1
vote
1 answer

What is the NSAboutURLProtocol class

When testing out my own URLProtocol subclass, I printed a list of the other subclasses the system knows about. I saw a "NSAboutURLProtocol" there. Does anyone know what it does?
CTMacUser
  • 1,996
  • 1
  • 16
  • 27
1
vote
1 answer

How to make sure, that my custom URL protocol is used?

According to the documentation of NSURLSessionConfiguration::protocolClasses, there is no guaranty, that my custom url protocol will be used. How can I ensure, that it is used whenever I set it to protocolClasses property? Prior to handling a…