Cuando se llama al método delegado imagePickerController: didFinishPickingMediaWithInfo: para UIImagePickerController, se obtiene la URL del activo para la foto seleccionada.
[info valueForKey:UIImagePickerControllerReferenceURL]
Ahora esta URL se puede usar para acceder al activo en ALAssetsLibrary. Entonces necesitaría una ALAssetRepresentation de ese activo al que se accede. A partir de este ALAssetRepresentation podemos obtener la UTI para esa imagen (http://developer.apple.com/library/ios/#DOCUMENTATION/FileManagement/Conceptual/understanding_utis/understand_utis_conc/understand_utis_conc.html)
Tal vez el código habría que sea un poco más claro:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
if (!(picker.sourceType == UIImagePickerControllerSourceTypeCamera)) {
NSLog(@"User picked image from photo library");
ALAssetsLibrary *library = [[[ALAssetsLibrary alloc] init] autorelease];
[library assetForURL:[info valueForKey:UIImagePickerControllerReferenceURL] resultBlock:^(ALAsset *asset) {
ALAssetRepresentation *repr = [asset defaultRepresentation];
if ([[repr UTI] isEqualToString:@"public.png"]) {
NSLog(@"This image is a PNG image in Photo Library");
} else if ([[repr UTI] isEqualToString:@"public.jpeg"]) {
NSLog(@"This image is a JPEG image in Photo Library");
}
} failureBlock:^(NSError *error) {
NSLog(@"Error getting asset! %@", error);
}];
}
}
Como explica la UTI, esto debe ser un tiro respuesta segura a la forma en la la imagen se almacena en la biblioteca de fotos.
A veces hay que cuidar, porque si haces UIImageJPEGRepresentation jpeg imagen de, es posible comprimir innecesariamente la imagen ya comprimida (perder la calidad y el tiempo de procesamiento). Por ejemplo, puede necesitar que la imagen seleccionada sea procesada posteriormente por la biblioteca, que solo acepta jpeg. –