Alex1987
Alex1987

Reputation: 9457

Cocoa: Getting Mime Type of a url?

I would like to get the Mime Type of a url synchronously. I don't want to use NSURLConnection. Just something like:

NSString *theMimeType = [self getMimeTypeFromURL:theURL];

Any ideas?

Upvotes: 3

Views: 5028

Answers (1)

Jacob Relkin
Jacob Relkin

Reputation: 163228

There is absolutely no reason not to use asynchronous requests.

Use NSURLConnection's delegate approach.

NSString        *url  = ...;
NSURLRequest    *req  = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
NSURLConnection *conn = [NSURLConnection connectionWithRequest:req delegate:self];
[conn start];

Somewhere else in your @implementation:

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {

   NSString *mime = [response MIMEType];
   //do something with mime
}

Upvotes: 9

Related Questions