NSURLConnection Crash Help Needed
NSURLConnection Crash Help Needed
- Subject: NSURLConnection Crash Help Needed
- From: Ryan Sutter <email@hidden>
- Date: Wed, 28 Dec 2005 14:55:00 -0600
Hi,
My app has a WebView in which a page can be loaded. I want the app
to figure out all the http and ftp links on that page and request the
response headers for each one in order to determine their mime-
types. I'm interested in links to audio, video and podcast files. I
created a class and added it to my NIB (it's not the main application
class) and added the following methods:
-(IBAction)findAllAddableElementsOnPage:(id)sender
{
WebFrame *theFrame = [webPageView mainFrame];
DOMDocument *theDocument = [theFrame DOMDocument];
DOMElement *rootElement = [theDocument documentElement];
DOMNodeList *links = [rootElement getElementsByTagName:@"a"];
NSLog(@"links count = %d", [links length]);
unsigned int i;
unsigned long count = [links length];
for (i = 0; i < count; i++) {
DOMElement *element = [links item:i];
NSString *href = [element getAttribute:@"href"];
NSArray *linkComponents = [href componentsSeparatedByString:@":"];
NSString *theProtocol = [linkComponents objectAtIndex:0];
if (([[theProtocol uppercaseString] hasPrefix:@"HTTP"] && !
[[theProtocol uppercaseString] hasPrefix:@"HTTPS"]) ||
[[theProtocol uppercaseString] hasPrefix:@"FTP"])
{
[NSURLConnection connectionWithRequest:[NSURLRequest
requestWithURL:[NSURL URLWithString:href]]
delegate:self];
}
}
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:
(NSURLResponse *)response
{
if ([[response MIMEType] hasPrefix:@"audio"] ) {
NSLog(@"Got response for url: %@ with mimeType: %@", [response
URL], [response MIMEType]);
}
// similar code for video and podcast snipped...
[connection cancel];
}
I ran the app and it works perfectly, except it randomly crashes with
an EXC_BAD_ACCESS, usually before completing the task.
I read in the NSURLConnection documentation about the delegate
needing to be on the default run loop or something like that and I
was wondering if maybe this is related to that or something.
Frankly, I'm not sure what that even means, so I'm kinda grabbing at
straws...
Any help would be greatly appreciated...
Ryan
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden