<Invalid CFStringRef> when reading metadata from image on iPhone
I read the image from the photo library and I get the metadata using the assets library. I then try to read the user comment exif tag and display it in my text view. Code is here:
[assetLibrary assetForURL:assestURL resultBlock:^(ALAsset *asset) {
ALAssetRepresentation *representation = [asset defaultRepresentation];
NSMutableDictionary *metadataDictPhoto = (NSMutableDictionary*)[representation metadata];
NSLog(@"This is the read metadata I believe: %@",[metadataDictPhoto description]);
metadataDictPhoto = metadataGlobal;
} failureBlock:^(NSError *error) {
NSLog(@"%@",[error description]);
}];
NSMutableDictionary *exifDictionary = (NSMutableDictionary*)[metadataGlobal objectForKey:(NSString*) kCGImagePropertyExifDictionary];
NSString *comment = (NSString*)[exifDictionary valueForKey:(NSString*)kCGImagePropertyExifUserComment];
textView.text = comment;
When I run it, there is no crashes but nothing is displayed in the textview. I have verified using NSLogs that the metadata received from my code is correct, as in I can see my custom exif user comment tag. If I place m开发者_开发知识库y mouse over comment it gives me the error . I can't get rid of this.
How can I read the string from the metadata dictionary and get it to display in the textView?
EDIT: DeePak Noticed that I mixed up an assignment statement and I changed it, but that did not fix the issue. While I was looking into this though I found that my NSLogs show that the code is that reads the metadata is passed over and then it runs the dictionary and string code which at this point the metadata isn't create. It then completes the imagepicker delegate function and then it eventually goes to the complete block and then runs the code and ouputs the dictionary and then I can see that everything is correct.
How could I get the code to run immediantly or have the program wait ntil the assetforurl completes?
You have this assignment flipped.
metadataDictPhoto = metadataGlobal;
You need to change this to
metadataGlobal = metadataDictPhoto;
metadataGlobal
is probably an instance variable which is why it is not crashing as it continues to be nil
here –
NSMutableDictionary *exifDictionary = (NSMutableDictionary*)[metadataGlobal objectForKey:(NSString*) kCGImagePropertyExifDictionary];
I fixed it by adding in the code outside of the completion block to inside the completion block and made sure all the variables were saved to be used then. This worked perfectly.
Now only if I could figure out why it is not writing IPTC correctly I would be set.
精彩评论