I use a web service in my iPhone application. The web service method returns a response that has several fields (for example, ID, description, etc.). One of these fields contains binary image data that I need to convert to UIImage in my iPhone application.
I have been using NSXMLParser successfully to extract data from an XML response. In the parser:foundCharacters: XMLParser selector, it gives an NSString* pointing to a line inside each field. Since this is a string, this is what I do to read image data when I encounter an image field:
UIImage *img = [[UIImage alloc] initWithData:[string dataUsingEncoding:NSUTF8StringEncoding]];
But the img variable is still "nil" after this line. It looks like the data from the XML string is not compatible with the conversion. What am I doing wrong here? (I can read other fields in my variables, but not in this image data field)
Thanks in advance.
source share