ALAssetsLibrary *lib = [[ALAssetsLibrary alloc] init];
[lib assetForURL:nil resultBlock:^(ALAsset *asset) {
NSDictionary *metadata = rep.metadata;
if (metadata) {
NSDictionary *GPSDict=metadata[@"{GPS}"];
NSDictionary *TIFFDict=metadata[@"{TIFF}"];
if (GPSDict){
double longitude = [[GPSDict objectForKey:@"Longitude"] doubleValue];
double latitude = [[GPSDict objectForKey:@"Latitude"] doubleValue];
if ([[GPSDict objectForKey:@"LatitudeRef"] isEqualToString:@"S"]) {
latitude = -latitude;
}
if ([[GPSDict objectForKey:@"LongitudeRef"] isEqualToString:@"W"]) {
longitude = -longitude;
}
if (TIFFDict){
NSUserDefaults *pref = [NSUserDefaults standardUserDefaults];
[pref setObject:[TIFFDict objectForKey:@"DateTime"] forKey:@"PHOTODATE"];
[pref synchronize];
}
coordinate2D = CLLocationCoordinate2DMake(latitude, longitude);
}else {
latitude = locationManager.location.coordinate.latitude;
longitude = locationManager.location.coordinate.longitude;
[GPSDictionary setObject:[NSNumber numberWithFloat:fabs(latitude)]
forKey:(NSString*)kCGImagePropertyGPSLatitude];
[GPSDictionary setObject:(latitude > 0 ? @"N": @"S") forKey:(NSString*)kCGImagePropertyGPSLatitudeRef];
[GPSDictionary setObject:[NSNumber numberWithFloat:fabs(longitude)]
forKey:(NSString*)kCGImagePropertyGPSLongitude];
[GPSDictionary setObject:(longitude > 0 ? @"E": @"W") forKey:(NSString*)kCGImagePropertyGPSLongitudeRef]; //
if (metadata&& GPSDictionary) {
[metadata setValue:GPSDictionary forKey:(NSString*)kCGImagePropertyGPSDictionary];
}
coordinate2D = CLLocationCoordinate2DMake(latitude, longitude);
}
}
else
{
}
} failureBlock:^(NSError *error) {
//User denied access
NSLog(@"Unable to access image: %@", error);
}];
I am using above code to get metadata of image.But now i want to edit this metadata.I want to add custom location in image if the location information is not present in the {GPS} dictionary.