I want to create a NSURLConnection delegate in Xcode 4.5.2 for iOS because the documentation suggests it. For now I am putting the following code (taken directly from the documentation) into my AppDelegate.m in the method application didFinishLaunchingWithOptions:.
// Create the request.
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com/"]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
// create the connection with the request
// and start loading the data
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) {
// Create the NSMutableData to hold the received data.
// receivedData is an instance variable declared elsewhere.
receivedData = [[NSMutableData data] retain];
} else {
// Inform the user that the connection failed.
}
How do I create the delegate in AppDelegate.h ?
Where and how do I declare the variable receivedData?
You shouldn’t be doing this in the AppDelegate, but just to make it work, here’s what you need to do.
1) In your AppDelegate.h, replace the interface declaration with this ::
2) In your AppDelegate.m, add this method ::