Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6582671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:18:36+00:00 2026-05-25T16:18:36+00:00

I have built a class that intercepts UIWebView resource loading by subclassing NSURLCache and

  • 0

I have built a class that intercepts UIWebView resource loading by subclassing NSURLCache and overriding cachedResponseForRequest:, similar to this example. Basically, if the requested resource is of type .css, I look for it in a local caches directory and if found, I load the local version.

The problem is that I now want to be able to specify which css files to look for in local cache, by providing a specific scheme that my app knows about. But when I change the scheme to something like:

 myapp://www.myhost.com/static/default.css

then cachedResponseForRequest: no longer gets called when the html is being loaded. Does anyone know why this, or how I can enable this method for my url with a specific scheme?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T16:18:37+00:00Added an answer on May 25, 2026 at 4:18 pm

    The key is to register your own subclass of NSURLProtocol, which can respond to your custom scheme in order to load those special resources. I used the following two methods:

    #pragma mark - Public
    
    + (void)enable {
        [NSURLProtocol registerClass:[MyAppURLProtocol class]];
    }
    
    #pragma mark - NSURLProtocol Overridden methods
    
    + (BOOL)canInitWithRequest:(NSURLRequest *)request {
        NSString *urlScheme = [[request URL] scheme];
        return [urlScheme isEqualToString:@"myapp"];
    }
    

    To register, call [MyAppURLProtocol enable] from the app delegate. You also need to override all other required methods defined in the NSURLProtocol reference, which ultimately forces you to load the data yourself..

    The reason why it is necessary to register your own url protocol is documented by apple as:

    The URL loading system design allows a client application to extend
    the protocols that are supported for transferring data. The URL
    loading system natively supports http, https, file, and ftp protocols.

    Custom protocols are implemented by subclassing NSURLProtocol and then
    registering the new class with the URL loading system using the
    NSURLProtocol class method registerClass:…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string that looks like this: Name1=Value1;Name2=Value2;Name3=Value3 Is there a built-in class/function
I have a Silverlight application that is built from a set of Silverlight class
I have a Windows service built upon ATL 7's CAtlServiceModuleT class. This service serves
I have built a js class that is have the control (html Control )
I have a POJO, and a (currently not-yet-built) class that will return Lists of
I have built a Custom Control Class that makes it much easier to build
I have built a custom Data Class that stores IP Address Details. Public Class
I have a class that looks like this: class Record { public string host
I have built a helper class that talks to a JSON service. The class
Does android have a built-in class that represents 2D vector? I need to do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.