我遵循Using NSURLConnection的指示,有時(非常非常少)我的項目在方法中崩潰。NSURLConnection在發佈NSMutableData時崩潰
- (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];
}
}
}
顯示來自崩潰的控制檯輸出和崩潰報告或堆棧跟蹤。另外,運行殭屍工具下的應用程序。 –
我一直試圖得到一些崩潰報告,但仍然沒有成功。我不知道什麼是殭屍工具... – iWheelBuy
我的應用程序運行在殭屍下,接下來應該怎麼做? – iWheelBuy