我知道如何从NSSURL获取数据,但是我想知道如何过滤数据,例如页面包含文本,图像,视频等,我如何指定只提取图像。并且让我们说如果所有数据一起下载我可以如何过滤它。
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
NSLog(@"%@",str);
[receivedData appendData:data];
}
与此类似,如果所有数据一起下载,我可以过滤。或者在下载之前指定数据类型。 thx提前
答案 0 :(得分:1)
从NSURLResponse
您可以查看MIMEType
NSURLResponse * httpResponse = (NSURLResponse *) response;
NSString *fileMIMEType = [[httpResponse MIMEType] lowercaseString];
您可以考虑将此委托方法用于NSURLConnection
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
NSString *mime = [response MIMEType];
//do something with mime
}