Как получить исходное имя файла фотографии в iOS?

В настоящее время я разрабатываю приложение для iPad, в котором пользователь вводит имя файла фотографии в текстовое поле (как часть примечаний к полю), а затем импортирует свои фотографии в библиотеку фотографий iPad. Приложение получит доступ к библиотеке с помощью ALAssetsLibrary и проведет перечисление фотографий в поисках тех, имя файла которых указано в примечаниях к полю. Это будет имя файла, присвоенное фотографии камерой, сделавшей ее. Например, «DSC_0019.JPG».

Разве это невозможно?

Я заметил, что если я импортирую фотографии с камеры на iPad, затем открываю iPhoto на своем Mac и смотрю на iPad как на камеру, я могу «получить информацию» об изображениях, хранящихся на iPad и увидеть оригинальное имя файла, которое я ищу. Однако это не содержится в метаданных на iPad.

Любая помощь будет принята с благодарностью.

Вот мой код:

(При работе с CFDictionary почти все равно null, кроме ключей Exif, у которых нет того, что я ищу)

- (void)viewDidLoad
{
    [super viewDidLoad];

    //start activity animation
    [self.activity setHidden:NO];
    [self.activity startAnimating];

    //init our arrays
    autoAssignedAssets  = [[NSMutableArray alloc] init];
    unAssignedRecords   = [[NSMutableArray alloc] init];
    unAssignedAssets    = [[NSMutableArray alloc] init];

    //setup the library
    ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];



    //[ BLOCK ] => assetEnumerator
    //
    void (^assetEnumerator)(ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {

        if (result != nil) {

            if ([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto] ) {


                //=================================================================

                ALAssetRepresentation* representation = [result defaultRepresentation];

                // create a buffer to hold the data for the asset's image
                uint8_t *buffer = (Byte*)malloc(representation.size);// copy the data from the asset into the buffer
                NSUInteger length = [representation getBytes:buffer fromOffset: 0.0  length:representation.size error:nil];

                // convert the buffer into a NSData object, free the buffer after
                NSData *adata = [[NSData alloc] initWithBytesNoCopy:buffer length:representation.size freeWhenDone:YES];

                // setup a dictionary with a UTI hint.  The UTI hint identifies the type of image we are dealing with (ie. a jpeg, png, or a possible RAW file)
                // specify the source hint
                NSDictionary* sourceOptionsDict = [NSDictionary dictionaryWithObjectsAndKeys: (id)[representation UTI] ,kCGImageSourceTypeIdentifierHint, nil];


                // create a CGImageSource with the NSData.  A image source can contain x number of thumbnails and full images.
                CGImageSourceRef sourceRef = CGImageSourceCreateWithData((CFDataRef) adata,  (CFDictionaryRef) sourceOptionsDict);

                [adata release];

                CFDictionaryRef imagePropertiesDictionary;

                // get a copy of the image properties from the CGImageSourceRef
                imagePropertiesDictionary = CGImageSourceCopyPropertiesAtIndex(sourceRef,0, NULL);

                //NSString *imageFilename = (NSString*)CFDictionaryGetValue(imagePropertiesDictionary, kCGImagePropertyCIFFImageFileName);

                NSLog(@"%@", (NSDictionary *)CFDictionaryGetValue(imagePropertiesDictionary, kCGImagePropertyExifDictionary));

                CFNumberRef imageWidth = (CFNumberRef)CFDictionaryGetValue(imagePropertiesDictionary, kCGImagePropertyPixelWidth);
                CFNumberRef imageHeight = (CFNumberRef)CFDictionaryGetValue(imagePropertiesDictionary, kCGImagePropertyPixelHeight);

                int w = 0;
                int h = 0;

                CFNumberGetValue(imageWidth, kCFNumberIntType, &w);
                CFNumberGetValue(imageHeight, kCFNumberIntType, &h);

                // cleanup memory
                CFRelease(imagePropertiesDictionary);
                CFRelease(sourceRef);

                //NSLog(@"width: %d, height: %d", w, h);
                //NSLog(@"%@", imageFilename);



                //=================================================================


                //NSDictionary *metadata = [[result defaultRepresentation] metadata];
                //NSLog(@"\n\nAsset Info: %@", result);
                //NSLog(@"\n\n\n\nMetaData: %@", metadata);
                [autoAssignedAssets addObject:result];

            }//end if photo

        }//end if

    }; //end assetEnumerator block



    //[ BLOCK ] => assetGroupEnumerator
    //
    void (^assetGroupEnumerator)(ALAssetsGroup *, BOOL *) =  ^(ALAssetsGroup *group, BOOL *stop) {

        if(group != nil) {
            [group enumerateAssetsUsingBlock:assetEnumerator];
        }//end if


        //now we're done, reload and stop animations
        [self.tableView reloadData];
        [self.activity stopAnimating];
        [self.activity setHidden:YES];

    }; //end assetGroupEnumerator block



    //[ BLOCK ] => failureBlock
    //
    void (^failureBlock)(NSError *) = ^(NSError *error) {

        NSString *errorTitle = [error localizedDescription];
        NSString *errorMessage = [error localizedRecoverySuggestion];
        NSString *errorFailureDesc = [error localizedFailureReason];

        NSLog(@"Error: %@, Suggestion: %@, Failure desc: %@", errorTitle, errorMessage, errorFailureDesc);

    }; //end failureBlock




    //loop over all the albums and process the pictures with the blocks above
    [library enumerateGroupsWithTypes:ALAssetsGroupAll usingBlock:assetGroupEnumerator failureBlock: failureBlock];


}//end viewDidLoad
15
задан JOM 10 October 2011 в 12:16
поделиться