IOS8. Photos application bug?

丶灬走出姿态 提交于 2019-12-06 05:17:34

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];
}];

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

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!