Hi, after play along to implement XML-RPC on IPhone finally I made it. I tried googling to find some articles that related to XML-RPC on IPhone, and those article drag me to WordPress application for IPhone. This application using XML RPC to communicate IPhone with the WordPress Blog, so the idea is grab the XML-RPC function from the WP application and implement it on our application. First we need to download WordPress for IPhone source code, you can download it here.
Once you download the source code, extract it. You will find a folder named Class, under the Class folder you will find XMLRPC folder. We need to import this folder (with the file inside) to our project, and also import NSString+XMLExtensions.h and NSString+XMLExtensions.m.
I will show you how to implement this XML-RPC on simple application.
Start your XCode program, make new “View-based Application” project.
Name the project with “XMLRPC-sayHello”.
Once the workspace opened, import the XMLRPC folder from WordPress source code to our project. Right click on Class folder, Add->Existing files
Then browse to the WordPress for Iphone source code, and select the XMLRPC folder. Click the “Add” button. The next is import the NSString+XMLExtensions.h and NSString+XMLExtensions.m files to our project.
Your project files will be look like this.
Ok the import step is done, now we need to design UI. We will make a simple interface with Label and Button only. The final design will be look like this.
To design the UI, double click the XMLRPC_SayHelloViewController.xib file and the interface builder will show up. On interface builder Drag a label from the library and change the text to “Response”. Next drag the Round Rect Button, and change the text to “Get Response”. Once done, close the interface builder and back to XCode.
Open the XMLRPC_SayHelloViewController.h, we will import the header files that used for XMLRPC, that are XMLRPCResponse.h, XMLRPCRequest.h, and XMLRPCConection.h. We also declare the label and the getResponse method in our header file. It should be look like this.
Once you done with the XMLRPC_SayHelloViewController.h, double click the XMLRPC_SayHelloViewController.xib to reopen the interface builder, we will connect the code with the interface. Open the Inspector window first Tools->Inspector.
Click the Response label in designer, then in the Inspector window it will be shown “New Referencing Outlet”. Drag the right circle of “New Referencing Outlet” to File’s Owner. See image.
When you release the mouse button, choose the “lblResponse” from the pop up window.
Ok, now select the Button on the interface, and drag the right circle button on the “Touch Down” inspector window to File’s Owner.
Once you finished editing the interface, save it and we continue with the coding.
Open the XMLRPC_SayHelloViewController.m and add the following code.
You can change the server path to your own path, and don’t forget to enable the XMLRPC on your wordpress installation. On wordpress XMLRPC there is demo.sayHello method that returns “hello” string, so I used this for the example.
Tadda! It’s done! Run the emulator by pressing command+enter button. Once running, press the “Get Response” button, that will invoke the getResponse method and show up the result to lblResponse.