views:

250

answers:

2

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
+3  A: 

Could you explain what you mean a little more? Are you saying that you want to:

  1. Monitor all HTTP connections the system makes?
  2. Monitor all HTTP communication within your app?
  3. 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
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