내 응용 프로그램은 여기에서와 같이 네트워크 연결을 사용하고 있습니다 :네트워크 연결을 처리하는 적절한 방법은 무엇입니까?
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
.
.
.
receivedData = [[NSMutableData alloc] init];
}
합니다.
-(void) dataFromWeb{
request = [[NSURLRequest alloc] initWithURL: url];
theConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if (theConnection) {
receivedData = [[NSMutableData data] retain];
NSLog(@"** NSURL request sent !");
} else {
NSLog(@"Connection failed");
}
.
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
.
.
.
[theConnection release];
[request release];
// Here - using receivedData
[receivedData release];
}
.
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[receivedData setLength:0];
}
.
- (void)connection:(NSURLConnection *)connection
didFailWithError:(NSError *)error
{
[theConnection release];
[request release];
[receivedData release];
}
.
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[receivedData appendData:data];
}
.
if (theConnection) {
// Create the NSMutableData to hold the received data.
// receivedData is an instance variable declared elsewhere.
receivedData = [[NSMutableData data] retain];
} else {
NSLog(@"Connection failed");
}
내가 이해하고 싶은 것은 :
내가 다른 동시 된 URLRequest를 만들고 싶었 경우에, 나는 다른를 사용해야합니다 응용 프로그램에서 도로 아래로이 조각 (onButtonPressed)입니다 웹에서 도착하는 데이터가 검색시에 섞이지 않도록 연결해야합니까? 이 코드에서
- , 무슨 일이 앱이 내가
receivedData=nil
내가if(receivedData!=nil) [receivedData setLength:0]; else receivedData = [[NSMutableData data] retain];
에 줄을 변경해야 보았다 추락 때로는 코드가 함수
didReceiveResponse()
이 라인이 무엇을하고 있는지 잘 모르겠다 receivedData = [[NSMutableData data] retain];
setLength:0
의 라인에 충돌 것입니다