gpt4 book ai didi

iphone - 是否有使用所有 NSURLConnection 委托(delegate)方法的完整示例?

转载 作者:行者123 更新时间:2023-12-03 18:50:26 24 4
gpt4 key购买 nike

我很难找到 NSURLConnection 委托(delegate)方法实现的任何示例。 Apple 的 SeismicXML 示例不完整。例如,他们不合并

-connection:willSendRequest:redirectResponse:

也许那里有一篇很好的文字。我已经浏览了所有与此相关的 Apple Material 。

最佳答案

这是我最近一直在使用的一个实现:

.h:
NSMutableData *responseData;

.m:
- (void)load {
NSURL *myURL = [NSURL URLWithString:@""];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:myURL
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:60];

[[NSURLConnection alloc] initWithRequest:request delegate:self];
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
responseData = [[NSMutableData alloc] init];
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[responseData appendData:data];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
[responseData release];
[connection release];
[textView setString:@"Unable to fetch data"];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(@"Succeeded! Received %d bytes of data",[responseData
length]);
NSString *txt = [[[NSString alloc] initWithData:responseData encoding: NSASCIIStringEncoding] autorelease];

}

关于iphone - 是否有使用所有 NSURLConnection 委托(delegate)方法的完整示例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2124421/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com