IOS8. Photos application bug?

2019-05-23 18:02发布

问题:

When I use filters in standard Photos application in IOS8, I can't get full metadata. I try two methods fetch metadata:

[manager requestImageDataForAsset:asset options:options resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) {
    CIImage *ciimage = [CIImage imageWithData:imageData];
    NSMutableDictionary *exif = [NSMutableDictionary dictionary];
    [exif addEntriesFromDictionary:ciimage.properties];
}];

[asset requestContentEditingInputWithOptions:editOptions completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) {
    CIImage *cimage = [CIImage imageWithContentsOfURL:contentEditingInput.fullSizeImageURL];
    NSMutableDictionary *exif = [NSMutableDictionary dictionary];
    [exif addEntriesFromDictionary:cimage.properties];
}];

I have not found any mention to the application Photos. I get such a result is always:

{
ColorModel = RGB;
DPIHeight = 72;
DPIWidth = 72;
Depth = 8;
Orientation = 1;
PixelHeight = 2592;
PixelWidth = 1936;
"{Exif}" =     {
    ColorSpace = 1;
    PixelXDimension = 1936;
    PixelYDimension = 2592;
};
"{JFIF}" =     {
    DensityUnit = 1;
    JFIFVersion =         (
        1,
        0,
        1
    );
    XDensity = 72;
    YDensity = 72;
};
"{TIFF}" =     {
    Orientation = 1;
};

Has anyone found a solution how to get the metadata of the images that have been edited in Photos?

I want see metadata like this:

回答1:

I found how fetch original metadata:

PHImageRequestOptions *options = [PHImageRequestOptions new];
options.networkAccessAllowed = YES;
options.synchronous = YES;
options.version = PHImageRequestOptionsVersionOriginal;

[manager requestImageDataForAsset:asset options:options resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) {
    CIImage *ciimage = [CIImage imageWithData:imageData];
    NSMutableDictionary *exif = [NSMutableDictionary dictionary];
    [exif addEntriesFromDictionary:ciimage.properties];
}];


回答2:

You can get creation date, modification date from properties of PHAsset. PHAsset properties



回答3:

I have tried the EXACT same code as well as every other alternative mechanism to retrieve the original image data from Photo app in the XCode IOS 8 simulator and the only thing that comes back for any image I in photo app under the simulator is virtually empty EXIF -- pretty much the same stuff illustrated in the original question.

Here's the question: Is this isolated to ONLY the simulator? Is there an issue with adding images to Photo app in the simulator via drag and drop?

PHImageManager.defaultManager().requestImageForAsset(assetImage as PHAsset, targetSize:PHImageManagerMaximumSize, contentMode: .AspectFill, options: nil, resultHandler: { (initialResult, _) in
        self.photoImageView.image = initialResult as UIImage
        println("WTF")
        println(initialResult)
    })

and this

PHImageManager.defaultManager().requestImageDataForAsset(assetImage, options: imageRequestOptions, resultHandler: { (imageData: NSData!, dataUti: String!, orientation: UIImageOrientation, _) in
        println("requestImageDataForAsset")
        println(imageData)
        let imageTest = CIImage(data: imageData)
        println(imageTest)
        let imageMeta = imageTest.properties()
        println(imageMeta)
    })

and this

        assetImage.requestContentEditingInputWithOptions(initialRequestOptions, completionHandler: { (input: PHContentEditingInput!, _)  -> Void in
        //Get full image
        let url = input.fullSizeImageURL
        let orientation = input.fullSizeImageOrientation
        var inputImage = CIImage(contentsOfURL: url)
        inputImage = inputImage.imageByApplyingOrientation(orientation)

        for (key, value) in inputImage.properties() {
            println("key: \(key)")
            println("value: \(value)")
        }
    })

all produce the same results in the XCode IOS simulator for 8.0/8.1.

Does your code work for the simulator? It appears to be the same as the second sample I provided that does not.



回答4:

It's so strange.

NSString *albumName = @"albumName"
PHFetchOptions *fetchOption = [[PHFetchOptions alloc]init];
fetchOption.predicate = [NSPredicate predicateWithFormat:@"title == %@",albumName];

PHFetchResult *result = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAlbumRegular options:fetchOption];

PHFetchOptions *fetchOption = [[PHFetchOptions alloc]init];
fetchOption.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]];
fetchOption.predicate = [NSPredicate predicateWithFormat:@"mediaType == 1"];
fetchOption.wantsIncrementalChangeDetails = YES;
PHFetchResult *result = [PHAsset fetchAssetsInAssetCollection:[result firstObject] options:nil];

//MetaData here is not complicated as you get
[result[0] requestContentEditingInputWithOptions:nil completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) {
    CIImage *image = [CIImage imageWithContentsOfURL:contentEditingInput.fullSizeImageURL];
    NSDictionary *metaData = [[NSDictionary alloc]initWithDictionary:image.properties];
    NSLog(@"metadata: %@", image.properties.description);
}];

Use the code above ,the metaData is just not complicated . And then..

NSString *type = [NSString stringWithFormat:@"mediaType == 1 && (pixelWidth != %f && pixelHeight != %f)",SCREEN_WIDTH*scale,SCREEN_HEIGHT*scale];

allPhotosfetchOption.predicate = [NSPredicate predicateWithFormat:type];
PHFetchResult *result = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:allPhotosfetchOption];

[result[0] requestContentEditingInputWithOptions:nil completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) {
    CIImage *image = [CIImage imageWithContentsOfURL:contentEditingInput.fullSizeImageURL];
    NSDictionary *metaData = [[NSDictionary alloc]initWithDictionary:image.properties];
    NSLog(@"metadata: %@", image.properties.description);
}];

Here I can get fully metadata...I think it is one bug of Photos.framework