Simplest Drupal iPhone App

Feb 7, 2009

Maybe not the most simple, but pretty close. This app posts a node to Drupal Services using XML-RPC. We thought it would be useful for anyone interested in building an iPhone app that interacts with Drupal and wanted a basic starting point. It provides two text fields and a submit button. Enter some text and press submit and the fields get posted to the Drupal site (the URL is hardcoded into the app, not very useful).

On the Drupal end, you will need the Services, the XML-RPC server, and the Node Service modules enabled (these are all bundled with Services). In addition you will have to disable keys and sessid in Services (Site Building > Services > Settings). Also you have to allow anonymous access to services, and allow anonymous creation of story nodes (both in User management > Permissions). So you really do not want to do this on any kind of production site.

The iPhone calls the method by posting the following XML:

<member><name>title</name><value><string>title text</string></value></member>
<member><name>body</name><value><string>body text</string></value></member>

The iPhone app provides two ways to accomplish this. The first (commented out in the code) creates a HTTP POST request with the XML above as the body. This is not very useful since you have to provide the raw XML, but it shows how to execute an HTTP POST which is useful for many other things. The second uses XML-RPC functionality borrowed from the open-source wordpress app (which itself is a version of the Cocoa XML-RPC Framework ). This makes it much easier to formulate and execute XML-RPC calls, and the whole thing boils down to this:

XMLRPCRequest *request = [[XMLRPCRequest alloc] initWithHost:[NSURL URLWithString: @""]];
NSMutableDictionary *postParams = [NSMutableDictionary dictionary];
[postParams setObject:@"story" forKey:@"type"];
[postParams setObject:titleString forKey:@"title"]; // title input from iphone
[postParams setObject:bodyString forKey:@"body"]; // body input from iphone
[request setMethod:@"" withObject:postParams];
XMLRPCResponse *nodeSaveResponse = [XMLRPCConnection sendSynchronousXMLRPCRequest:request];

The full app below. Developed with iPhone SDK 2.2.

simpleNodeTitleBody-XMLRPC.zip899.47 KB

Related posts

Jun 6, 2014 | Posted by: David Hamme
We are excited to annouce that Zivtech CEO Alex Urevick-Ackelsberg will be discussing the future of Drupal in business on a panel with other local Drupal shops including Context, Rock River Star, and Tabula Creative.    Businesses have long been searching for a platform that empowers...
Mar 24, 2014 | Posted by: David Hamme
Are you an aspiring web developer, fresh out of college and eager to dive into Philly’s exploding tech startup scene? Are you a growing startup or established company in need of talented developers to help take your business to the next level?   Zivtech was thrilled last week when...
Mar 10, 2014 | Posted by: Jason Moore
Hi, my name is Jason Moore and I am a Developer here at Zivtech. I recently started working for Zivtech full time, helping their talented team continue to build and maintain awesome Drupal websites and applications for their clients. For the three years prior to joining Zivtech, I built a name for...
Nov 5, 2013 | Posted by: David Hamme
A salute to the unsung modules that make our jobs a little easier. We at Zivtech have been working with Drupal for a long time, some of us for over 10 years, and in that time we’ve gotten to use (and sometimes build) a lot of really cool modules to develop stellar sites for our clients. We...
Sep 26, 2013 | Posted by: Laurence Liss
As a Senior Developer here at Zivtech, part of my job is to develop with an eye towards security. If you follow development and security news, you know that achieving security is pretty hard in complex systems. But, while correctly implementing security across a site is challenging, some aspects...
Sep 11, 2013 | Posted by: Alban Bailly
Drupal Page: GitHub: Live Demo:   My Name is Alban and I'm a front-end dev here at Zivtech. We use an installation profile called Bear and I have been working on a theme to go along...
Apr 16, 2013 | Posted by: Jody Hamilton
The quality assurance (QA) phase of a web development project is the last phase before launch. While the development team has a lot of experience with QA phases, oftentimes the client team is new to the process, which can lead to stress. Let's prevent this with a little Q&A on QA. What is...
Apr 15, 2013 | Posted by: David Marvin
Nominees for the 17th annual Webby Awards have been announced! And Zivtech-built sites are in the running for four awards! The recently-launched Greatist is nominated for best health website, while is nominated for best Charitable Organizations/Non-Profit website,...
Feb 14, 2013 | Posted by: Alex Urevick-Ackelsberg
This weekend nine members of the Zivtech staff are participating and competing in Startup Weekend Health Philadelphia 2013, which, according to their site, "centers on building a web or mobile application that could be the basis for a credible business. After 500+ Startup Weekends world-wide...
Feb 11, 2013 | Posted by: Mason Wendell
We love Responsive Web Design, and we love Drupal. But do they love each other? After working on a number of RWD and Drupal projects this year, I'm happy to report that they get along just fine. Though "Love" might be stretching it a bit. Can Drupal and RWD be Pals? Drupal is a great platform...