Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
The Drupal iOS iPhone & iPad Software Development Kit provides a full suite of iOS features to natively connect iOS applications to Drupal. Formerly KBDrupalConnect
Objective-C C
Branch: 7.x-3.x
Pull request Compare This branch is 118 commits behind kylebrowning:3.x.

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
NSData_Base64
DIOSComment.h
DIOSComment.m
DIOSConfig.h
DIOSConnect.h
DIOSConnect.m
DIOSFile.h
DIOSFile.m
DIOSNode.h
DIOSNode.m
DIOSTaxonomy.h
DIOSTaxonomy.m
DIOSUser.h
DIOSUser.m
DIOSViews.h
DIOSViews.m
LICENSE
README.md

README.md

Drupal iOS SDK - Connect your iOS/OS X app to Drupal

What you need to know

The Drupal iOS SDK is a standard set of libraries for communicating to Drupal from any iOS device. Its extremely simple. This GETs you a Drupal node and stores it in an NSDictionary, myNode.

DIOSNode *node = [[DIOSNode alloc] initWithSession:session];
NSDictionary *myNode = [node nodeGet:1];
[node release];

What you need to get started

XCode

  • This library
  • the following frameworks
    • UIKit.Framework
    • CoreGraphics.framework
    • CFNetwork.framework
    • libz.1.2.3.dylib
    • SystemConfiguration.framework
    • MobileCoreServices.framework
    • ASIHTTPRequest which can be found here
  • Update DIOSConfig.h with the correct API_KEYS SERVICES_URL and DOMAIN (make sure you checkout the drupal-ios-sdk branch for your version of drupal eg. 6.x-2.x, 6.x-3.x or 7.x-3.x)

Drupal 6.x-2.x (NOT RECOMMENDED, Services 2.x is running 5 year old code. I would suggest using 3.x now that it is in RC stage.

Drupal 6.x-3.x and 7.x-3.x (RECOMMENDED)

Note, Services 3.x does not have an API key, it doesn't use them, IT HAS BEEN REMOVED. Use oAuth if you need extra Security.

Demo Code (Code is pulled from http://github.com/workhabitinc/drupal-ios-sdk-example)

Demo Setup (Services 3.x) http://vimeo.com/22635252

Session

DIOSConnect *session = [[DIOSConnect alloc] init];

Views

DIOSViews *views = [[DIOSViews alloc] initWithSession:session];
[views initViews];
[views addParam:[viewNameField text] forKey:@"view_name"];
[views addParam:[NSArray arrayWithObjects:[argsField text], nil] forKey:@"args"];
[views addParam:[displayNameField text] forKey:@"display_id"];
[views runMethod];
[views release];

Node

Add

DIOSNode *node = [[DIOSNode alloc] initWithSession:session];
NSMutableDictionary *nodeData = [[NSMutableDictionary alloc] init];
[nodeData setObject:[bodySaveField text] forKey:@"body"];
[nodeData setObject:[typeSaveField text] forKey:@"type"];
[nodeData setObject:[titleSaveField text] forKey:@"title"];
[nodeData setObject:[nidSaveField text] forKey:@"nid"];
[nodeData setObject:@"now" forKey:@"date"];
[nodeData setObject:@"1" forKey:@"status"];
[nodeData setObject:[[session userInfo] objectForKey:@"name"] forKey:@"name"];
[node nodeSave:nodeData];
[node release];

Delete

DIOSNode *node = [[DIOSNode alloc] initWithSession:session];
[node nodeDelete:[nidDeleteField text]];
[node release];

Get

DIOSNode *node = [[DIOSNode alloc] initWithSession:session];
[node nodeGet:[nidGetField text]];
[node release]; 

Comment

Add

DIOSComment *comment = [[DIOSComment alloc] initWithSession:session];
[comment addComment:[nidCommentAddField text] subject:[subjectCommentAddField text] body:[bodyCommentAddField text]];
[comment release]; 

Get

DIOSComment *comment = [[DIOSComment alloc] initWithSession:session];
[comment getComment:[nidCommentGetField text]];
[comment release]; 

User

Login

DIOSUser *user = [[DIOSUser alloc] initWithSession:session];
[user loginWithUsername:[usernameLoginField text] andPassword:[passwordLoginField text]];
[user release];

Logout

DIOSUser *user = [[DIOSUser alloc] initWithSession:session];
[user logout];
[user release];

Save

DIOSUser *user = [[DIOSUser alloc] initWithSession:session];
NSMutableDictionary *userData = [[NSMutableDictionary alloc] init];
[userData setObject:[usernameSaveField text] forKey:@"name"];
[userData setObject:[passwordSaveField text] forKey:@"pass"];
[userData setObject:[emailSaveField text] forKey:@"mail"];
[userData setObject:[uidSaveField text] forKey:@"uid"];
[user userSave:userData];
[user release];

Get

DIOSUser *user = [[DIOSUser alloc] initWithSession:session];
[user userGet:[uidGetField text]];
[user release];

Delete

DIOSUser *user = [[DIOSUser alloc] initWithSession:session];
[user userDelete:[uidDeleteField text]];
[user release];

Taxonomy

- (NSMutableArray *) getTreeForVid:(NSString*)vid {
  DIOSTaxonomy *taxonomy = [[DIOSTaxonomy alloc] initWithSession:session];
  return [[taxonomy getTree:vid] objectForKey:@"#data"];
}

- (NSMutableArray *) getNodesForTid:(NSString*)tid {
  DIOSTaxonomy *taxonomy = [[DIOSTaxonomy alloc] initWithSession:session];

  return [[taxonomy selectNodes:tid] objectForKey:@"#data"];
}

Troubleshooting

If you are getting Access denied, or API Key not valid, double check that your key settings are setup correctly at admin/build/services/keys and double check that permissions are correct for your user and anonymous.

X service doesnt exist in Drupal iOS SDK

Thats ok, just subclass DIOSConnect and follow the model of tthe other DIOS classes. If its a core services Class and I have not added it in, please help us all out and contribute it by by doing a pull request. Thanks!

Questions

Email kyle@workhabit.com

Something went wrong with that request. Please try again.