Client

open class Client : Credential

This class provides a representation of a Kinvey environment holding App ID and App Secret. Please never use a Master Secret in a client application.

  • Shared client instance for simplicity. Use this instance if you don’t need to handle with multiple Kinvey environments.

    Declaration

    Swift

    public static let shared: Client
  • Undocumented

    Declaration

    Swift

    public static var sharedClient: Client { get }
  • Undocumented

    Declaration

    Swift

    public typealias UserChangedListener = (User?) -> Void
  • Undocumented

    Declaration

    Swift

    public var userChangedListener: UserChangedListener?
  • It holds the User instance after logged in. If this variable is nil means that there’s no logged user, which is necessary for some calls to in a Kinvey environment.

    Declaration

    Swift

    open internal(set) var activeUser: User? { get set }
  • Holds the App ID for a specific Kinvey environment.

    Declaration

    Swift

    open fileprivate(set) var appKey: String? { get }
  • Holds the App Secret for a specific Kinvey environment.

    Declaration

    Swift

    open fileprivate(set) var appSecret: String? { get }
  • Holds the Host for a specific Kinvey environment. The default value is https://baas.kinvey.com/

    Declaration

    Swift

    open private(set) var apiHostName: URL { get }
  • Holds the Authentication Host for a specific Kinvey environment. The default value is https://auth.kinvey.com/

    Declaration

    Swift

    open private(set) var authHostName: URL { get }
  • Cache policy for this client instance.

    Declaration

    Swift

    open var cachePolicy: NSURLRequest.CachePolicy
  • Hold default optional values for all calls made by this Client instance

    Declaration

    Swift

    open var options: Options?
  • The default value for apiHostName variable.

    Declaration

    Swift

    public static let defaultApiHostName: URL
  • The default value for authHostName variable.

    Declaration

    Swift

    public static let defaultAuthHostName: URL
  • Set a different schema version to perform migrations in your local cache.

    Declaration

    Swift

    open fileprivate(set) var schemaVersion: CUnsignedLongLong? { get }
  • Use this variable to handle push notifications.

    Declaration

    Swift

    open fileprivate(set) var push: Push! { get }
  • Set a different type if you need a custom User class. Extends from User allows you to have custom properties in your User instances.

    Declaration

    Swift

    open var userType: User.Type
  • Default Value for DataStore tag

    Declaration

    Swift

    public static let defaultTag: String
  • Enables logging for any network calls.

    Declaration

    Swift

    open var logNetworkEnabled: Bool
  • Stores the MIC API Version to be used in MIC calls

    Declaration

    Swift

    open var micApiVersion: MICApiVersion?
  • Default constructor. The initialize method still need to be called after instanciate a new instance.

    Declaration

    Swift

    public init()
  • Constructor that already initialize the client. The initialize method is called automatically.

    Declaration

    Swift

    public convenience init<U: User>(
        appKey: String,
        appSecret: String,
        instanceId: String,
        accessGroup: String? = nil,
        schema: Schema? = nil,
        options: Options? = nil,
        completionHandler: ((Swift.Result<U?, Swift.Error>) -> Void)? = nil
    )
  • Constructor that already initialize the client. The initialize method is called automatically.

    Declaration

    Swift

    public convenience init<U: User>(
        appKey: String,
        appSecret: String,
        accessGroup: String? = nil,
        apiHostName: URL = Client.defaultApiHostName,
        authHostName: URL = Client.defaultAuthHostName,
        schema: Schema? = nil,
        compactCacheOnLaunch: Bool = true,
        options: Options? = nil,
        completionHandler: ((Swift.Result<U?, Swift.Error>) -> Void)? = nil
    )
  • Initialize a Client instance with all the needed parameters and requires a boolean to encrypt or not any store created using this client instance.

    Declaration

    Swift

    @available(*, deprecated, message: "Deprecated in version 3.17.0. Please use Client.initialize(appKey:appSecret:accessGroup:apiHostName:authHostName:encrypted:schema:completionHandler:(Result<User?, Swift.Error>﹚ -> Void")
    open func initialize<U: User>(
        appKey: String,
        appSecret: String,
        accessGroup: String? = nil,
        apiHostName: URL = Client.defaultApiHostName,
        authHostName: URL = Client.defaultAuthHostName,
        encrypted: Bool,
        schema: Schema? = nil,
        completionHandler: @escaping User.UserHandler<U>
    )
  • Initialize a Client instance with all the needed parameters and requires a boolean to encrypt or not any store created using this client instance.

    Declaration

    Swift

    open func initialize<U: User>(
        appKey: String,
        appSecret: String,
        accessGroup: String? = nil,
        apiHostName: URL = Client.defaultApiHostName,
        authHostName: URL = Client.defaultAuthHostName,
        encrypted: Bool,
        schema: Schema? = nil,
        compactCacheOnLaunch: Bool = true,
        options: Options? = nil,
        completionHandler: @escaping (Swift.Result<U?, Swift.Error>) -> Void
    )
  • Initialize a Client instance with all the needed parameters.

    Declaration

    Swift

    @available(*, deprecated, message: "Deprecated in version 3.17.0. Please use Client.initialize(appKey:appSecret:accessGroup:apiHostName:authHostName:encryptionKey:schema:completionHandler:(Result<U?, Swift.Error>﹚ -> Void﹚ instead")
    open func initialize<U: User>(
        appKey: String,
        appSecret: String,
        accessGroup: String? = nil,
        apiHostName: URL = Client.defaultApiHostName,
        authHostName: URL = Client.defaultAuthHostName,
        encryptionKey: Data? = nil,
        schema: Schema? = nil,
        compactCacheOnLaunch: Bool = true,
        completionHandler: @escaping User.UserHandler<U>
    )
  • Initialize a Client instance.

    • appKey: App Key value from Kinvey Console
    • appSecret: App Secret value from Kinvey Console
    • instanceId: Prefix value of Host URL from Kinvey Console. eg: my-instance if the Host URL looks like my-instance-baas.kinvey.com
    • accessGroup: Access Group for Keychain
    • encrypted: Enable encryption for cache
    • schema: Migration Schema to be used in case a migration is required
    • options: Custom Options to be used instead of default values
    • completionHandler: Completion Handler async call

    Declaration

    Swift

    open func initialize<U: User>(
        appKey: String,
        appSecret: String,
        instanceId: String,
        accessGroup: String? = nil,
        encrypted: Bool,
        schema: Schema? = nil,
        compactCacheOnLaunch: Bool = true,
        options: Options? = nil,
        completionHandler: @escaping (Swift.Result<U?, Swift.Error>) -> Void
    )
  • Initialize a Client instance.

    Declaration

    Swift

    open func initialize<U: User>(
        appKey: String,
        appSecret: String,
        instanceId: String,
        accessGroup: String? = nil,
        encryptionKey: Data? = nil,
        schema: Schema? = nil,
        compactCacheOnLaunch: Bool = true,
        options: Options? = nil,
        completionHandler: @escaping (Swift.Result<U?, Swift.Error>) -> Void
    )

    Parameters

    appKey

    App Key value from Kinvey Console

    appSecret

    App Secret value from Kinvey Console

    instanceId

    Prefix value of Host URL from Kinvey Console. eg: my-instance if the Host URL looks like my-instance-baas.kinvey.com

    accessGroup

    Access Group for Keychain

    encryptionKey

    Encryption Key for cache

    schema

    Migration Schema to be used in case a migration is required

    options

    Custom Options to be used instead of default values

    completionHandler

    Completion Handler async call

  • Initialize a Client instance with all the needed parameters.

    Declaration

    Swift

    open func initialize<U: User>(
        appKey: String,
        appSecret: String,
        accessGroup: String? = nil,
        apiHostName: URL = Client.defaultApiHostName,
        authHostName: URL = Client.defaultAuthHostName,
        encryptionKey: Data? = nil,
        schema: Schema? = nil,
        compactCacheOnLaunch: Bool = true,
        options: Options? = nil,
        completionHandler: @escaping (Swift.Result<U?, Swift.Error>) -> Void
    )
  • Autorization header used for calls that don’t requires a logged User.

    Declaration

    Swift

    open var authorizationHeader: String? { get }
  • Check if the appKey and appSecret properties are correct doing a ping call to the server.

    Declaration

    Swift

    @available(*, deprecated, message: "Deprecated in version 3.17.1. Please use Client.ping(completionHandler:﹚ instead")
    @discardableResult
    public func ping(completionHandler: @escaping (EnvironmentInfo?, Swift.Error?) -> Void) -> AnyRequest<Swift.Result<EnvironmentInfo, Swift.Error>>
  • Checks connectivity to your backend. A successful response returns a summary of your backend environment and confirms that the app can talk to the backend.

    Declaration

    Swift

    @discardableResult
    public func ping(completionHandler: @escaping (Swift.Result<EnvironmentInfo, Swift.Error>) -> Void) -> AnyRequest<Swift.Result<EnvironmentInfo, Swift.Error>>