StitchAppClient
public protocol StitchAppClient
The StitchAppClient
has the fundamental set of methods for communicating with a MongoDB
Stitch application backend.
An implementation can be initialized or retrieved using the Stitch
utility class.
This protocol provides access to the StitchAuth
for login and authentication.
Using serviceClient
, you can retrieve services, including the RemoteMongoClient
for reading
and writing on the database. To create a RemoteMongoClient
, pass remoteMongoClientFactory
into serviceClient(fromFactory:withName)
.
You can also use it to execute Stitch Functions.
Finally, its StitchPush
object can register the current user for push notifications.
-
The
StitchAuth
object representing the authentication state of this client. Includes methods for logging in and logging out.Important
Authentication state can be persisted beyond the lifetime of an application. A StitchAppClient retrieved from theStitch
singleton may or may not be authenticated when first initialized.Declaration
Swift
var auth: StitchAuth { get }
-
The push notifications component of the app. This is used for registering the currently signed in user for push notifications.
Declaration
Swift
var push: StitchPush { get }
-
Retrieves a general-purpose service client for the Stitch service associated with the specified name. Use this for services which do not have a well-defined interface in the SDK.
Declaration
Swift
func serviceClient(withServiceName serviceName: String) -> StitchServiceClient
Parameters
withServiceName
The name of the desired service in MongoDB Stitch.
-
Retrieves the service client for the Stitch service associated with the specified name and factory.
Declaration
Swift
func serviceClient<T>(fromFactory factory: AnyNamedServiceClientFactory<T>, withName serviceName: String) -> T
Parameters
fromFactory
An
AnyNamedServiceClientFactory
object which contains aNamedServiceClientFactory
class which will provide the client for this service. Each available service has a static factory which can be used for this method.withName
The name of the service as defined in the MongoDB Stitch application.
Return Value
a service client whose type is determined by the
T
type parameter of theAnyNamedServiceClientFactory
passed in thefromFactory
parameter. -
Retrieves the service client for the Stitch service associated with the specificed factory.
Declaration
Swift
func serviceClient<T>(fromFactory factory: AnyNamedServiceClientFactory<T>) -> T
Parameters
fromFactory
An
AnyNamedServiceClientFactory
object which contains aNamedServiceClientFactory
class which will provide the client for this service. Each available service has a static factory which can be used for this method.Return Value
a service client whose type is determined by the
T
type parameter of theAnyNamedServiceClientFactory
passed in thefromFactory
parameter. -
Retrieves the service client for the Stitch service associated with the service type with the specified factory.
Declaration
Swift
func serviceClient<T>(fromFactory factory: AnyThrowingServiceClientFactory<T>) throws -> T
Parameters
fromFactory
An
AnyThrowingServiceClientFactory
object which contains aThrowingServiceClientFactory
class which will provide the client for this service. Each available service has a static factory which can be used for this method.Return Value
a service client whose type is determined by the
T
type parameter of theAnyThrowingServiceClientFactory
passed in thefromFactory
parameter. -
Retrieves the service client for the Stitch service associated with the specified name and factory.
Declaration
Swift
func serviceClient<T>(fromFactory factory: AnyNamedThrowingServiceClientFactory<T>, withName serviceName: String) throws -> T
Parameters
fromFactory
An
AnyNamedThrowingServiceClientFactory
object which contains aNamedThrowingServiceClientFactory
class which will provide the client for this service. Each available service has a static factory which can be used for this method.withName
The name of the service as defined in the MongoDB Stitch application.
Return Value
a service client whose type is determined by the
T
type parameter of theAnyNamedServiceClientFactory
passed in thefromFactory
parameter.
-
Calls the MongoDB Stitch function with the provided name and arguments, and decodes the result of the function into a
Decodable
type as specified by theT
type parameter.Declaration
Swift
func callFunction<T: Decodable>(withName name: String, withArgs args: [BSONValue], _ completionHandler: @escaping (StitchResult<T>) -> Void)
Parameters
withName
The name of the Stitch function to be called.
withArgs
The
BSONArray
of arguments to be provided to the function.completionHandler
The completion handler to call when the function call is complete. This handler is executed on a non-main global
DispatchQueue
. If the operation is successful, the result will contain aT
representing the decoded result of the function call. -
Calls the MongoDB Stitch function with the provided name and arguments, ignoring the result of the function.
Declaration
Swift
func callFunction(withName name: String, withArgs args: [BSONValue], _ completionHandler: @escaping (StitchResult<Void>) -> Void)
Parameters
withName
The name of the Stitch function to be called.
withArgs
The
BSONArray
of arguments to be provided to the function.completionHandler
The completion handler to call when the function call is complete. This handler is executed on a non-main global
DispatchQueue
. -
Calls the MongoDB Stitch function with the provided name and arguments, and decodes the result of the function into a
Decodable
type as specified by theT
type parameter. Also accepts a timeout. Use this for functions that may run longer than the client-wide default timeout (15 seconds by default).Declaration
Swift
func callFunction<T: Decodable>(withName name: String, withArgs args: [BSONValue], withRequestTimeout requestTimeout: TimeInterval, _ completionHandler: @escaping (StitchResult<T>) -> Void)
Parameters
withName
The name of the Stitch function to be called.
withArgs
The
BSONArray
of arguments to be provided to the function.withRequestTimeout
The number of seconds the client should wait for a response from the server before failing with an error.
completionHandler
The completion handler to call when the function call is complete. This handler is executed on a non-main global
DispatchQueue
. If the operation is successful, the result will contain aT
representing the decoded result of the function call. -
Calls the MongoDB Stitch function with the provided name and arguments, ignoring the result of the function. Also accepts a timeout. Use this for functions that may run longer than the client-wide default timeout (15 seconds by default).
Declaration
Swift
func callFunction(withName name: String, withArgs args: [BSONValue], withRequestTimeout requestTimeout: TimeInterval, _ completionHandler: @escaping (StitchResult<Void>) -> Void)
Parameters
withName
The name of the Stitch function to be called.
withArgs
The
BSONArray
of arguments to be provided to the function.withRequestTimeout
The number of seconds the client should wait for a response from the server before failing with an error.
completionHandler
The completion handler to call when the function call is complete. This handler is executed on a non-main global
DispatchQueue
.