martes, 15 de junio de 2010

My WebServices solution for iPhone

I got into the necessity to call WebServices from within an iPhone application I was designing. After a small search with Google I found different implementations, even a “C” (or C++ I can’t recall) library, but nothing like the “easy way” used in Dot Net.

My specific application needs to show address book, kind of, information in a table. Each row shows the contact’s picture and name; when selected, in a second screen, detailed information will be show. This functionality is similar to the contacts' section of
Facebook or LinkedIn application. The source information has to be gathered from a WebService.

Note: I will focus these articles in the WebService consumption, instead of the Graphical development and application logic.

For simplification, the WebService contract will be:
1.List screen
An XLM with up to 100 results with the next structure:
<contact>
<contactid>id for this item</contactid>
<photo>Url of contact’s photo</photo>
<name>contact’s name</name>
</contact>

2.Detail screen
An XML with contact’s detail:
<contactdetail>
<detail1>bunch of information</detail1>
<detail2>bunch of information</detail2>
<otherdetail1>bunch of information</otherdetail1>
...
</contactdetail>
Details might vary according with the available information, even tag names might change

In the first screen, information from first WebService Method is used to populate the table, the photo URL is use to download the image and draw it in the same table for each contact.

Once a row is selected, the second method is called with the ID of the contact, the retrieved information will be shown in a way similar to built in Contacts’ application.

First Stage was to develop a File Downloader class. This class helps me to download information of a given URL. With this class I test downloading a hardcoded XML simulating a call to first method.

Despite the fact I also build a generic all purpose XML Parser, which I might talk in a different post, the Second Stage was to think in downloading several files at a same time, to show the photos in the main contacts’ list. So, I build a Download Controller class to keep track of downloads and the objects requesting downloads. This controller uses the file Downloader build in First Stage.

In a Third Stage I create a WebService Controller class to support the call of registered WebServices. This class publishes the WebServices which will be called to retrieve information; it uses the Download Controller from Second Stage and, by consequence, the File Downloader from First Stage.

The final WebService Controller gave me an “easy way” to call WebServices from my iPhone applications as now, I only need to type down the Methods’ Firms in ordet to be available to use.

In the Next post I'll talk about the impementation stages.

No hay comentarios: