Can't edit photo metadata using AssetsLibrary in iOS 8.3 (works in 8.2)

My app takes photos, saves them to camera roll and allows EXIF ​​metadata to be changed.

I am using AssetsLibrary to save and modify a photo (I cannot use the new PhotoKit api because I need to change the base EXIF, plus its a legacy application and it will take a lot of refactoring to change it).

I am using Xcode 6.3.1 with iOS 8.3 SDK, 6.1 deployment target.

In iOS 8.2 it all worked.

IOS 8.3 does not edit metadata.

The app has permission in privacy settings to access photos.

When a user modifies a photo and the app tries to overwrite the photo, iOS 8.3 now displays the Allow App to Change This Photo dialog box. This dialog did not appear in iOS 8.2. If I click Edit, the photo is saved, but the metadata is erased. There is also no error returned by the setImageData function and I check if the photo being edited is available.

Here is the code:

-(void)savePhoto:(ALAsset*)asset
{
    ALAssetRepresentation* rep = [asset defaultRepresentation];
    CGImageRef imageRef = [rep fullResolutionImage];
    UIImage *image = [UIImage imageWithCGImage:imageRef];
    NSData *imageData = UIImageJPEGRepresentation(image, 1.0);

    if ([asset isEditable])
    {
        [asset setImageData:imageData metadata:self.getMetadataDictionary completionBlock:^(NSURL *assetURL, NSError *error)
         {
             if (error!=nil)
                 [self showErrorDialog:error title:@"Error saving photo" ];

             [self closeSaveDialog];
         }];
    }
    else
    {
        [self closeSaveDialog];
        UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Error saving photo" message:@"Photo is not editable" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alertView show];
    }
}

      

When I was debugging this, I noticed a bug in my code where the photo was resized by 4 times using UIImageJPEGRepresentation because it resampled the photo, so I changed the code to grab the original bytes of the image and just rewrite the metadata. But I wonder I have a different error, this time setImageData returns this error.

Description: "The user denied access."

Basic error: "ALAssetsLibraryErrorDomain" ID -3311.

FailureReason: "The user denied the application access to their media."

Which is strange because the app has created an asset and it has access to the camera frame.

Again, this code works in iOS 8.2:

-(void)savePhoto:(ALAsset*)asset
{
    ALAssetRepresentation* rep = [asset defaultRepresentation];
    // New way handling updating photos, doesn't modify image data at all, only metadata
    Byte *buffer = (Byte*)malloc((unsigned long)rep.size);
    NSUInteger buffered = [rep getBytes:buffer fromOffset:0.0 length:(NSUInteger)rep.size error:nil];
    NSData *imageData = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES];
    if ([asset isEditable])
    {
        [asset setImageData:imageData metadata:self.getMetadataDictionary completionBlock:^(NSURL *assetURL, NSError *error)
         {
             if (error!=nil)
                 [self showErrorDialog:error title:@"Error saving photo" ];

             [self closeSaveDialog];
         }];
    }
    else
    {
        [self closeSaveDialog];
        UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Error saving photo" message:@"Photo is not editable" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alertView show];
    }
}

      

I submitted a bug report to Apple, but did not hear anything.

It's similar to this question: setImageData doesn't work in iOS 8.3

Does anyone know of a fix for this?

Thank,

+3


source to share





All Articles