Sealyu

          --- 博客已遷移至: http://www.sealyu.com/blog

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            618 隨筆 :: 87 文章 :: 225 評論 :: 0 Trackbacks

          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 node.save method by posting the following XML:

          <methodName>node.save</methodName>
          <params>
          <param><value><struct>
          <member><name>type</name><value><string>story</string></value></member>
          <member><name>title</name><value><string>title text</string></value></member>
          <member><name>body</name><value><string>body text</string></value></member>
          </struct></value></param>
          </params></methodCall>

          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: @"http://192.168.1.14/drupal-6.6/services/xmlrpc"]];
          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:@"node.save" withObject:postParams];
          XMLRPCResponse *nodeSaveResponse = [XMLRPCConnection sendSynchronousXMLRPCRequest:request];

          The full app below. Developed with iPhone SDK 2.2.

          AttachmentSize
          simpleNodeTitleBody-XMLRPC.zip 899.47 KB
          posted on 2010-09-15 13:53 seal 閱讀(282) 評論(0)  編輯  收藏 所屬分類: PHPiPhone
          主站蜘蛛池模板: 池州市| 锡林郭勒盟| 武安市| 田林县| 赞皇县| 义马市| 八宿县| 彰化市| 红安县| 合阳县| 睢宁县| 山东省| 信宜市| 广德县| 射洪县| 石渠县| 瑞昌市| 神农架林区| 灌阳县| 金寨县| 呼玛县| 新营市| 拉萨市| 亚东县| 玉环县| 彩票| 栾川县| 香河县| 天峨县| 武川县| 阳信县| 博乐市| 阆中市| 阿图什市| 禹州市| 剑河县| 申扎县| 武山县| 托克托县| 鄂托克旗| 寿宁县|