Skip to content

The Drupal iOS iPhone & iPad Software Development Kit provides a full suite of iOS features to natively connect iOS applications to Drupal. Formerly KBDrupalConnect

License

Notifications You must be signed in to change notification settings

ohdonpiano/drupal-ios-sdk

 
 

Repository files navigation

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 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 [email protected]

About

The Drupal iOS iPhone & iPad Software Development Kit provides a full suite of iOS features to natively connect iOS applications to Drupal. Formerly KBDrupalConnect

Resources

License

Stars

Watchers

Forks

Packages

No packages published