注册 登录  
 加关注
查看详情
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

云水禅心

淡若秋菊何妨瘦, 清到梅花不畏寒.

 
 
 

日志

 
 

XML-RPC on IPhone  

2012-04-28 13:18:39|  分类: iphone |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

http://www.leoganda.net/xml-rpc-on-iphone/

https://github.com/eczarny/xmlrpc

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.

Picture 1

Name the project with “XMLRPC-sayHello”.

Picture 2

Once the workspace opened, import the XMLRPC folder from WordPress source code to our project. Right click on Class folder, Add->Existing files

Picture 3

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.

Picture 4

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.

Picture 5

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.

Coding

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.

Picture 7

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.

Picture-8

When you release the mouse button, choose the “lblResponse” from the pop up window.

Picture 9

Ok, now select the Button on the interface, and drag the right circle button on the “Touch Down” inspector window to File’s Owner.

Picture 10

Once you finished editing the interface, save it and we continue with the coding.

Open the XMLRPC_SayHelloViewController.m and add the following code.

Picture 11

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.

Download source

  评论这张
 
阅读(606)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018