我想在 Xcode 4.5.2 for iOS 中创建一个 NSURLConnection 委托,因为文档建议这样做。现在我将以下代码(直接取自文档)放入我的 AppDelegate.m 方法中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.
}
如何在 AppDelegate.h 中创建委托?我在哪里以及如何声明变量receivedData
?