I have made an iphone application in which data is retrieved from remote server through xml saved. I want to retrieve images also with in the XMl and have to show them in
In my application I am both sending and receiving images through Xml. In order to facilitate this, I encode/decode the images using base64 encoding. MY encode/decode methods live in 2 objective-c categories, 1 for NSData and 1 for NSString. You call these methods on the respective data types, I have listed examples below. The methods are [NSData base64Encoding] and [NSString base64Decoding].
When sending to the server...
NSLog(@"Compressing Image: JPEG 80%");
NSData *imgData = UIImageJPEGRepresentation(scaledImage, 0.8f);
NSString *b64String = [imgData base64Encoding];
My "b64String" variable now has a base64 encoded string representation of my image. You can now wrap this in Xml and use your normal NSURLConnection to send it to the server.
When receiving from the sever... (Make sure you are sending base64 encoded text from the server)
You will do your normal Xml parsing, here my "value" variable holds the base64 string from the server.
NSData *imgData = [value base64Decoding];
UIImage *image = [[UIImage alloc] initWithData:imgData];
You should be able to look up some common base64 encoding/decoding algorithms in Objective-C, let me know if you would like me to post my methods (they are kinda long so I obmitted them here).
I'm writing an app at the moment that has this problem - I've solved it by putting a url to the image in the xml instead of embedding the image data itself. For example my xml looks something like this :
<images>
<image url="http://www.example.com/images/12345.jpg" />
<image url="http://www.example.com/images/67890.jpg" />
</images>
As I'm parsing the xml, when I hit an < image > tag I store the url in an NSMutalbeArray. When the xml is parsed I loop through the array and get each image using NSURLConnection.
Sam
PS I worked out how to use NSURLConnection from this page : https://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLConnection.html