Wednesday, May 1, 2013

NSURLResponse MIMEType example ios


MIMEType

Returns the receiver’s MIME type.
- (NSString *)MIMEType
Return Value of [NSURLResponse MIMEType]
The receiver’s MIME type.
Discussion of [NSURLResponse MIMEType]
The MIME type is often provided by the response’s originating source. However, that value may be changed or corrected by a protocol implementation if it can be determined that the response’s source reported the information incorrectly.
If the response’s originating source does not provide a MIME type, an attempt to guess the MIME type may be made.
Example of [NSURLResponse MIMEType]
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {

   NSString *mime = [response MIMEType];
   //do something with mime
}
Example of [NSURLResponse MIMEType]
 [archiver encodeObject:[response URL] forKey:@"URL"];
 [archiver encodeObject:[response MIMEType] forKey:@"MIMEType"];
 [archiver encodeObject:[NSNumber numberWithLongLong:[response expectedContentLength]] forKey:@"expectedContentLength"];
 [archiver encodeObject:[response textEncodingName] forKey:@"textEncodingName"];

    // Decode:

 NSURL *url = [unarchiver decodeObjectForKey:@"URL"];
 NSString *mimeType = [unarchiver decodeObjectForIKey:@"MIMEType"];
 NSNumber *expectedContentLength = [unarchiver decodeObjectForKey:@"expectedContentLength"];
 NSString *textEncodingName = [unarchiver decodeObjectForKey:@"textEncodingName"];

 NSURLResponse* response = [[NSHTTPURLResponse alloc] initWithURL:url MIMEType:mimeType expectedContentLength:[expectedContentLength longLongValue] textEncodingName:textEncodingName];