I'd like to pretend to be new to CocoaTouch but since I've been using it for over a year I'll just jump right out and claim stoopidity. Is there an easy/elegant way to intercept HTTP calls in CocoaTouch and route them through a custom class. In Java I could implement a custom protocol handler and change the URL protocol from "http:" to something like "myproto:". Is there something similar in ObjC?
A:
You can have an application register to handle URL schemes. This is set in the Info.plist entries for the application:
CFBundleURLTypes (URL types): An array of URL types that the application can handle. Each URL type is a dictionary that defines the schemes (such as http or mailto) that the application can handle. This property allows applications to register custom URL schemes.
This is used for communication between applications. If you want to intercept requests from inside your application and rewrite the URLs, I'm pretty sure that's relatively easy to do in the UIWebView delegate methods.
Mark Bessey
2009-07-02 20:55:33
+3
A:
Could you explain what you mean a little more? Are you saying that you want to:
- Monitor all HTTP connections the system makes?
- Monitor all HTTP communication within your app?
- Implement a custom URL scheme for data loading that you have full control over?
If the number 3, you want to look at NSURLProtocol
Mike Abdullah
2009-07-03 10:13:52
Yes, the NSURLProtocol was the thing I was looking for. Analogous to Java protocol handlers it allows me to implement a custom URL scheme/protocol for loading data I have control over.
Cliff
2009-07-21 12:39:05