The Drupal iOS Software Development Kit provides a full suite of iOS methods to natively connect iOS applications to Drupal 7 and 8.
Swift Ruby
Latest commit 80b940c Jul 27, 2016 @kylebrowning committed on GitHub Fixes a hardcoded url.

README.md

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

built by Kyle Browning

Introduction

The Drupal iOS SDK is a standard set of libraries for communicating to Drupal from any iOS device. Its extremely simple, and is basically a wrapper for Alamofire. It combines the most used commands to communicate with Drupal and handles session managment for you.

Requirements

DIOS Version Drupal Version Min iOS Target Notes
4.x Drupal 8 (Swift) iOS 9.0
3.x Drupal 8 (Obj-C) iOS 7.0
2.x Drupal 6-7 (Obj-C) iOS 5.0 Requires Services module

Philosophy and Purpose

At its core the Drupal iOS SDK is designed to handle everything Drupal Core supports out of the box. Since 8.x is in its infancy, more and more features will come available as Drupal aims to improve its API capabilities.

Current 4.x features

  • Session management
  • Entity Crud

Future

In the future this project will have more robust features that make working with Drupal from a Swift perspective easier such as:

  • LoginViewController
  • SignupViewController
  • LogoutButton
  • Views integration into Table Views

Installation


Create a pod file with (this will keep you on the 4.0 releases which is Drupal 8 specific)

 pod 'DIOS', '~> 4.0'

Then run

pod install

Configuration

  1. Copy the plist file from this repository or make your own and called it dios.plist
  2. Edit the diosurlkey to point to your domain
  3. (Optional) If you're not using HTTPS you will have to enable the http://stackoverflow.com/questions/31254725/transport-security-has-blocked-a-cleartext-http

Initialization Steps

The code below will give you access to the baseline of features for communicating to a Drupal site.

//Create an instance to use.
let dios = DIOS.sharedInstance

This will log you into the site.

//set Username and password
dios.setUserNameAndPassword("kylebrowning", password: "password")

Entity Requests

//we need an entity manager instance
let em = DIOSEntity()

Get

let em = DIOSEntity()

//Get Node 36
em.get("node", entityId: "36") { (success, response, json, error) in
    if (success) {
        print(json)
    } else {
        print(error)
    }
}

Create/post

//build our node body
let body = [
    "type": [
        [
            "target_id": "article"
        ]
    ],
    "title": [
        [
            "value": "Hello World"
        ]
    ],
    "body": [
        [
            "value": "How are you?"
        ]
    ]
]

//Create a new node.
em.post("node", params: body) { (success, response, json, error) in
    if (success) {
        print(response)
    } else {
        print(error)
    }
}

Update/Put/PATCH

//Update an existing node
em.patch("node", entityId: "36", params: body) { (success, response, json, error) in
    if (success) {
        //Extra error checking, but its not needed
        if (response!.response?.statusCode == 201) {
            print(json)
        }
    } else {
        print(error)
    }
}

Delete

//Delete an existing node
em.delete("node", entityId: "26") { (success, response, json, error) in
    if (success) {
        print(response)
    } else {
        print(error)
    }
}