Waterwheel makes using Drupal as a backend with iOS, macOS, tvOS, or watchOS enjoyable by combining the most used features of Drupal's API's in one SDK. - Formerly known as Drupal iOS SDK.
If you do not want to use Basic Auth, and instead use a cookie, waterwheel provides an authentication method for doing so.
Sessions are handled for you, and will restore state upon closing an app and reopening it.
Waterwheel provides a waterwheelAuthButton to place anywhere in your app. The code below is iOS specific because of its dependence on UIKit.
let loginButton =waterwheelAuthButton()
// When we press Login, lets show our Login view controller.
loginButton.didPressLogin= {
waterwheel.login(usernameField.text!, password: passwordField.text!) { (success, response, json, error) inif (success) {
print("successful login")
} else {
print("failed to login")
}
}
}
loginButton.didPressLogout= { (success, error) inprint("logged out")
}
self.view.addSubview(loginButton)
Taking this one step further, waterwheel also provides a waterwheelLoginViewController. You can subclass this controller and overwrite if needed. For our purposes we will use the default implementation.
First, we build our waterwheelLoginViewController and set our loginRequestCompleted and logoutRequestCompleted closures:
// Lets build our default waterwheelLoginViewController.let vc =waterwheelLoginViewController()
//Lets add our closure that will be run when the request is completed.
vc.loginRequestCompleted= { (success, error) inif (success) {
// Do something related to a successful loginprint("successful login")
self.dismissViewControllerAnimated(true, completion: nil)
} else {
print (error)
}
}
vc.logoutRequestCompleted= { (success, error) inif (success) {
print("successful logout")
// Do something related to a successful logoutself.dismissViewControllerAnimated(true, completion: nil)
} else {
print (error)
}
}
Once that is done we can now tell our waterwheelAuthButton what to do when someone presses Login. Of course this can all be handled manually in your own implementation, but for our purposes, were just using what waterwheel provides.
Here we instantiate a new waterwheelAuthButton and tell it what we want to happen when someone presses login, and logout.
let loginButton =waterwheelAuthButton()
// When we press Login, lets show our Login view controller.
loginButton.didPressLogin= {
// Lets Present our Login View Controller since this closure is for the loginButton pressself.presentViewController(vc, animated: true, completion: nil)
}
loginButton.didPressLogout= { (success, error) inprint("logged out")
}
self.view.addSubview(loginButton)
Because these two Views know whether you are logged in or out, they will always show the correct state of buttons(Login, or Logout) and perform the approriate actions. The UI is up to you, but at its default you get username, password, submit, and cancel button. With all that said, you can ingore these classes and use the methods that waterwheel provides and deeply integrate into your own UI.
The framework is tracking Drupal 8. As new features come out in 8, they will be added ASAP. Since Drupal 7 and Drupal 8 are completely different in terms of API's, you will need to use the correct version of waterwheel depending on your Drupal version.
Requirements
iOS 8.0+ / Mac OS X 10.9+ / tvOS 9.0+ / watchOS 2.0+
请发表评论