1.第一种方法,根据url的后缀
NSString * path = photo.resUrl;
NSString *extensionName = path.pathExtension;
if ([extensionName.lowercaseString isEqualToString:@"gif"]) {
imageType = @"image/gif";
}else{
imageType = @"no";
}
第二种,取出图片数据的第一个字节,根据字节判断,必须说明url必须是可以正常网络请求的url
NSData * data = [NSData dataWithContentsOfURL:[NSURL URLWithString:photo.resUrl]];
uint8_t c;
[data getBytes:&c length:1];
NSString * imageType = nil;
switch (c) {
case 0xFF:
imageType = @"image/jpeg";
case 0x89:
imageType = @"image/png";
case 0x47:
imageType = @"image/gif";
case 0x49:
case 0x4D:
imageType = @"image/tiff";
case 0x52:
default:
break;
}