1

I have created a custom camera using AVFoundation, now after capturing images, I need to save them in the iPhone's gallery.

I tried saving images with UIImageWriteToSavedPhotosAlbum but found that this does not save EXIF information.

Vikram Parimi
  • 777
  • 6
  • 29
  • you can create directory with application name and you can save image in your application directory only. – Sagar Bhut Aug 23 '18 at 13:45
  • for saving exif information see this : https://stackoverflow.com/questions/9006759/how-to-write-exif-metadata-to-an-image-not-the-camera-roll-just-a-uiimage-or-j?rq=1 – Shahzaib Qureshi Aug 23 '18 at 14:38

1 Answers1

0

To Save EXIF information with an image refer below code.

    - (void)saveImageDataToPhotoAlbum:(NSData *)originalData  
{  
    NSDictionary *dataDic = [self getDataAndMetadata:originalData];  

    ALAssetsLibrary *assetsLib = [[ALAssetsLibrary alloc] init];  
    [assetsLib writeImageDataToSavedPhotosAlbum:dataDic[@"data"]  
                                       metadata:dataDic[@"metadata"]  
                                completionBlock:^(NSURL *url, NSError *e) {  
                                    [self addToMyAlbum:url];  
                                }];  
}  
- (NSDictionary *)getDataAndMetadata:(NSData *)originalData  
{  
    CGImageSourceRef cimage = CGImageSourceCreateWithData((CFDataRef)originalData, nil);  
    NSDictionary *metadata = (NSDictionary *)CGImageSourceCopyPropertiesAtIndex(cimage, 0, nil);  

    NSMutableDictionary *metadataAsMutable = [NSMutableDictionary dictionaryWithDictionary:metadata];  
    metadataAsMutable[(NSString *)kCGImagePropertyGPSDictionary] = self.myGpsDic;  

    NSMutableData *dataForMetadataRemoval = [NSMutableData data];  
    CGImageDestinationRef dest =  
    CGImageDestinationCreateWithData((CFMutableDataRef)dataForMetadataRemoval, CGImageSourceGetType(cimage), 1, nil);  
    CGImageDestinationAddImageFromSource(dest, cimage, 0, (CFDictionaryRef)metadataAsMutable);  
    CGImageDestinationFinalize(dest);  
    CFRelease(dest);  
    [metadata release];  
    CFRelease(cimage);  

    return @{ @"data" : (dataForMetadataRemoval), @"metadata" : metadataAsMutable};  
}  
 return metadataAsMutable;   
}  
Bhavesh Patel
  • 596
  • 4
  • 17