DDPClient
public class DDPClient: NSObject
DDPClient is the base class for communicating with a server using the DDP protocol
-
Undocumented
Declaration
Swift
public class DDPClient: NSObject -
Undocumented
Declaration
Swift
public class DDPClient: NSObject
-
Boolean value that determines whether the
Declaration
Swift
public var allowSelfSignedSSL:Bool = false -
Sets the log level. The default value is .None. Possible values: .Verbose, .Debug, .Info, .Warning, .Error, .Severe, .None
Declaration
Swift
public var logLevel = XCGLogger.LogLevel.None -
Creates a random String id
Declaration
Swift
public func getId() -> String -
Makes a DDP connection to the server
Declaration
Swift
public func connect(url:String, callback:DDPConnectedCallback?)Parameters
urlThe String url to connect to, ex.
wss://todos.meteor.com/websocket
callbackA closure that takes a String argument with the value of the websocket session token
-
Executes a method on the server. If a callback is passed, the callback is asynchronously executed when the method has completed. The callback takes two arguments: result and error. It the method call is successful, result contains the return value of the method, if any. If the method fails, error contains information about the error.
Declaration
Swift
public func method(name: String, params: AnyObject?, callback: DDPMethodCallback?) -> StringParameters
nameThe name of the method
paramsAn object containing method arguments, if any
callbackThe closure to be executed when the method has been executed
-
Sends a subscription request to the server.
Declaration
Swift
public func sub(name: String, params: [AnyObject]?) -> StringParameters
nameThe name of the subscription
paramsAn object containing method arguments, if any
-
Sends a subscription request to the server. If a callback is passed, the callback asynchronously runs when the client receives a ‘ready’ message indicating that the initial subset of documents contained in the subscription has been sent by the server.
Declaration
Swift
public func sub(name:String, params: [AnyObject]?, callback: DDPCallback?) -> StringParameters
nameThe name of the subscription
paramsAn object containing method arguments, if any
callbackThe closure to be executed when the server sends a ‘ready’ message
-
Sends an unsubscribe request to the server. - parameter name: The name of the subscription - parameter callback: The closure to be executed when the server sends a ‘ready’ message
Declaration
Swift
public func unsub(withName name: String) -> [String]Parameters
nameThe name of the subscription
callbackThe closure to be executed when the server sends a ‘ready’ message
-
Sends an unsubscribe request to the server. If a callback is passed, the callback asynchronously runs when the client receives a ‘ready’ message indicating that the subset of documents contained in the subscription have been removed.
Declaration
Swift
public func unsub(withId id: String, callback: DDPCallback?)Parameters
nameThe name of the subscription
callbackThe closure to be executed when the server sends a ‘ready’ message
-
Executes when a subscription is ready.
Declaration
Swift
public func subscriptionIsReady(subscriptionId: String, subscriptionName:String) {}Parameters
subscriptionIdA String representation of the hash of the subscription name
subscriptionNameThe name of the subscription
-
Executes when a subscription is removed.
Declaration
Swift
public func subscriptionWasRemoved(subscriptionId:String, subscriptionName:String) {}Parameters
subscriptionIdA String representation of the hash of the subscription name
subscriptionNameThe name of the subscription
-
Executes when the server has sent a new document.
Declaration
Swift
public func documentWasAdded(collection:String, id:String, fields:NSDictionary?)Parameters
collectionThe name of the collection that the document belongs to
idThe document’s unique id
fieldsThe documents properties
-
Executes when the server sends a message to remove a document.
Declaration
Swift
public func documentWasRemoved(collection:String, id:String)Parameters
collectionThe name of the collection that the document belongs to
idThe document’s unique id
-
Executes when the server sends a message to update a document.
Declaration
Swift
public func documentWasChanged(collection:String, id:String, fields:NSDictionary?, cleared:[String]?)Parameters
collectionThe name of the collection that the document belongs to
idThe document’s unique id
fieldsOptional object with EJSON values containing the fields to update
clearedOptional array of strings (field names to delete)
-
Executes when the server sends a message indicating that the result of a method has changed.
Declaration
Swift
public func methodWasUpdated(methods:[String])Parameters
methodsAn array of strings (ids passed to ‘method’, all of whose writes have been reflected in data messages)
-
Executes when the client receives an error message from the server. Such a message is used to represent errors raised by the method or subscription, as well as an attempt to subscribe to an unknown subscription or call an unknown method.
Declaration
Swift
public func didReceiveErrorMessage(message: DDPError)Parameters
messageA DDPError object with information about the error
-
Sends a subscription request to the server.
Declaration
Swift
public func subscribe(name:String) -> String { return sub(name, params:nil) }Parameters
nameThe name of the subscription
-
Sends a subscription request to the server.
Declaration
Swift
public func subscribe(name:String, params:[AnyObject]) -> String { return sub(name, params:params) }Parameters
nameThe name of the subscription
paramsAn object containing method arguments, if any
-
Sends a subscription request to the server. If a callback is passed, the callback asynchronously runs when the client receives a ‘ready’ message indicating that the initial subset of documents contained in the subscription has been sent by the server.
Declaration
Swift
public func subscribe(name:String, params:[AnyObject]?, callback: DDPCallback?) -> String { return sub(name, params:params, callback:callback) }Parameters
nameThe name of the subscription
paramsAn object containing method arguments, if any
callbackThe closure to be executed when the server sends a ‘ready’ message
-
Sends a subscription request to the server. If a callback is passed, the callback asynchronously runs when the client receives a ‘ready’ message indicating that the initial subset of documents contained in the subscription has been sent by the server.
Declaration
Swift
public func subscribe(name:String, callback: DDPCallback?) -> String { return sub(name, params:nil, callback:callback) }Parameters
nameThe name of the subscription
callbackThe closure to be executed when the server sends a ‘ready’ message
-
Asynchronously inserts a document into a collection on the server
Declaration
Swift
public func insert(collection: String, document: NSArray, callback: DDPMethodCallback?) -> StringParameters
collectionThe name of the collection
documentAn NSArray of documents to insert
callbackA closure with result and error arguments describing the result of the operation
-
Asynchronously inserts a document into a collection on the server
Declaration
Swift
public func insert(collection: String, document: NSArray) -> StringParameters
collectionThe name of the collection
documentAn NSArray of documents to insert
-
Synchronously inserts a document into a collection on the server. Cannot be used on the main queue.
Declaration
Swift
public func insert(sync collection: String, document: NSArray) -> ResultParameters
collectionThe name of the collection
documentAn NSArray of documents to insert
-
Asynchronously updates a document into a collection on the server
Declaration
Swift
public func update(collection: String, document: NSArray, callback: DDPMethodCallback?) -> StringParameters
collectionThe name of the collection
documentAn NSArray of documents to update
callbackA closure with result and error arguments describing the result of the operation
-
Asynchronously updates a document on the server
Declaration
Swift
public func update(collection: String, document: NSArray) -> StringParameters
collectionThe name of the collection
documentAn NSArray of documents to update
-
Synchronously updates a document on the server. Cannot be used on the main queue
Declaration
Swift
public func update(sync collection: String, document: NSArray) -> ResultParameters
collectionThe name of the collection
documentAn NSArray of documents to update
-
Asynchronously removes a document on the server
Declaration
Swift
public func remove(collection: String, document: NSArray, callback: DDPMethodCallback?) -> StringParameters
collectionThe name of the collection
documentAn NSArray of documents to remove
callbackA closure with result and error arguments describing the result of the operation
-
Asynchronously removes a document into a collection on the server
Declaration
Swift
public func remove(collection: String, document: NSArray) -> StringParameters
collectionThe name of the collection
documentAn NSArray of documents to remove
-
Synchronously removes a document into a collection on the server. Cannot be used on the main queue.
Declaration
Swift
public func remove(sync collection: String, document: NSArray) -> ResultParameters
collectionThe name of the collection
documentAn NSArray of documents to remove
-
Undocumented
Declaration
Swift
public class DDPClient: NSObject -
Logs a user into the server using an email and password
Declaration
Swift
public func loginWithPassword(email: String, password: String, callback: DDPMethodCallback?)Parameters
emailAn email string
passwordA password string
callbackA closure with result and error parameters describing the outcome of the operation
-
Logs a user into the server using a username and password
Declaration
Swift
public func loginWithUsername(username: String, password: String, callback: DDPMethodCallback?)Parameters
usernameA username string
passwordA password string
callbackA closure with result and error parameters describing the outcome of the operation
-
Attempts to login a user with a token, if one exists
Declaration
Swift
public func loginWithToken(callback: DDPMethodCallback?) -> BoolParameters
callbackA closure with result and error parameters describing the outcome of the operation
-
Undocumented
Declaration
Swift
public class DDPClient: NSObject -
Invokes a Meteor method to create a user account with a given email and password on the server
Declaration
Swift
public func signupWithEmail(email: String, password: String, callback: ((result:AnyObject?, error:DDPError?) -> ())?) -
Invokes a Meteor method to create a user account with a given email and password, and a NSDictionary containing a user profile
Declaration
Swift
public func signupWithEmail(email: String, password: String, profile: NSDictionary, callback: ((result:AnyObject?, error:DDPError?) -> ())?) -
Invokes a Meteor method to create a user account with a given username, email and password, and a NSDictionary containing a user profile
Declaration
Swift
public func signupWithUsername(username: String, password: String, email: String?, profile: NSDictionary?, callback: ((result:AnyObject?, error:DDPError?) -> ())?) -
Returns the client userId, if it exists
Declaration
Swift
public func userId() -> String? -
Returns the client’s username or email, if it exists
Declaration
Swift
public func user() -> String? -
Logs a user out and removes their account data from NSUserDefaults
Declaration
Swift
public func logout() -
Logs a user out and removes their account data from NSUserDefaults. When it completes, it posts a notification: DDP_USER_DID_LOGOUT on the main queue
Declaration
Swift
public func logout(callback:DDPMethodCallback?)Parameters
callbackA closure with result and error parameters describing the outcome of the operation
-
Automatically attempts to resume a prior session, if one exists
Declaration
Swift
public func resume(url:String, callback:DDPCallback?)Parameters
urlThe server url
-
Connects and logs in with an email address and password in one action
Declaration
Swift
public convenience init(url: String, email: String, password: String, callback: DDPMethodCallback?)Parameters
urlString url, ex. wss://todos.meteor.com/websocket
emailString email address
passwordString password
callbackA closure with result and error parameters describing the outcome of the operation
-
Returns true if the user is logged in, and false otherwise
Declaration
Swift
public func loggedIn() -> Bool
DDPClient Class Reference