Reputation: 5389
I am building a SDK targeted at developers in my corporation, both at the head office and abroad. This SDK is implemented as a Singleton and provides the developers with data objects acquired (when possible) from our corporate servers.
I intend to configure NSURLSessionConfiguration, using NSURLCache's sharedURLCache, when the SDK is initialized, but I am afraid that, being shared, the cache settings would later on be altered by the application developers, possibly leading to obscure bugs.
Is there a better way?
Upvotes: 0
Views: 35
Reputation: 626
Assuming you are comfortable with Objective-c and Swizzling:
You could add an NSURLProtocol to intercept the relevant calls and manage their caching separately.
Then, to prevent other NSURLProtocols from overriding your own (they are checked in the order they are registered), you could swizzle the call to register a new NSURLProtocol [NSURLProtocol registerClass:[MyURLProtocol class]];
and in your alternate imp always make sure you add your NSURLProtocol as the last one.
I would make sure this is well documented and communicated to any developer using your sdk to make sure she understands that her NSURLProtocol will ALWAYS loose president over your NSURLProtocol
here are some references to Swizzling, and NSURLProtocol from the the one and only NSHipster...
Upvotes: 3