NSURLConnectionの使用の指示に従いましたが、プロジェクトがメソッドでクラッシュすることがあります(非常にまれです)。
- (void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
[connection release];
[myNSMutableData release];
}
を解放しようとするとクラッシュしNSMutableData
ます。なぜクラッシュするのか知りたい!
私が使用するいくつかのコード:
- (void) start
{
while (1)
{
NSString *stringURL = @"http://www.iwheelbuy.com/get.php?sex=1";
NSURL *url = [NSURL URLWithString:stringURL];
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:5.0];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if (connection)
{
getData = [[NSMutableData data] retain];
break;
}
else
{
NSLog(@"no start connection");
}
}
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
if ([connection.originalRequest.URL.absoluteString rangeOfString:@"get.php"].location != NSNotFound)
{
[getData setLength:0];
}
}
- (void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
if ([connection.originalRequest.URL.absoluteString rangeOfString:@"get.php"].location != NSNotFound)
{
[connection release];
[getData release];
}
}
- (void) connectionDidFinishLoading:(NSURLConnection *)connection
{
if ([connection.originalRequest.URL.absoluteString rangeOfString:@"get.php"].location != NSNotFound)
{
[connection release];
NSString *html = [[NSString alloc] initWithData:getData encoding:NSASCIIStringEncoding];
[getData release];
if ([html rangeOfString:@"id1="].location != NSNotFound && [html rangeOfString:@"id2="].location != NSNotFound)
{
NSLog(@"everything is OKAY");
[html release];
}
else
{
[html release];
[self start];
}
}
}