DigiMe
public final class DigiMe
The entry point to the SDK
-
Undocumented
Declaration
Swift
public var isDownloadingFiles: Bool { get }
-
The log levels for all
DigiMe
instances which will be included in logs. Defaults to[.info, .warning, .error, .critical]
Declaration
Swift
public class var logLevels: [LogLevel] { get set }
-
Sets the custom log handler for all
DigiMe
instances to allow logging to a different system. DigiMeSDK usesNSLog
by default.Declaration
Swift
public class func setLogHandler(_ handler: @escaping LogHandler)
Parameters
handler
The log handler block
-
Initialises a new instance of SDK. A new instance should be created for each contract the app uses
Declaration
Swift
public init(configuration: Configuration)
Parameters
configuration
The configuration which defines this instance
-
Authorizes the contract configured with this digi.me instance to access to a library.
Requires
CallbackService.shared().handleCallback(url:)
to be called from appropriate inAppDelegate
orSceneDelegate
place so that authorization can complete.If the user has not already authorized, will present a view controller in which user consents. If user has already authorized, refreshes the authorization, if necessary (which may require user consent again).
To authorize this contract to access the same library that another contract has been authorized to access, specify the contract to link to’s credentials. This is useful when a read contract needs to access the same library that a write contract has written deta to.
Additionally for read contracts:
- Upon first authorization, can optionally specify a service from which user can log in to and retrieve data.
Creates of refreshes a session during which data can be read from library.
Declaration
Swift
public func authorize(credentials: Credentials? = nil, serviceId: Int? = nil, readOptions: ReadOptions? = nil, linkToContractWithCredentials linkCredentials: Credentials? = nil, resultQueue: DispatchQueue = .main, completion: @escaping (Result<Credentials, SDKError>) -> Void)
Parameters
credentials
The existing credentials for the contract to authorize. If nil, will create credentials on success
serviceId
Identifier of initial service to add. Only valid for first authorization of read contracts where user has not previously granted consent. Ignored for all subsequent calls.
readOptions
Options to filter which data is read from sources for this session. Only used for read contracts.
linkToContractWithCredentials
When specified, connects to same library as another contract. Does nothing if user has already authorized this contract.
resultQueue
The dispatch queue which the completion block will be called on. Defaults to main dispatch queue.
completion
Block called upon authorization completion with new or refreshed credentials, or any errors encountered.
-
Once a user has granted consent, adds an additional service. Also initiates synchronization of data from this service to user’s library.
Declaration
Swift
public func addService(identifier: Int, credentials: Credentials, resultQueue: DispatchQueue = .main, completion: @escaping (Result<Credentials, SDKError>) -> Void)
Parameters
identifier
Identifier of service to add.
credentials
The existing credentials for the contract.
resultQueue
The dispatch queue which the completion block will be called on. Defaults to main dispatch queue.
completion
Block called upon completion with new or refreshed credentials, or any errors encountered
-
Reads the service data source accounts user has added to library related to the configured contract.
Requires a valid session to have been created, either implicitly by adding a new service, or explicitly by calling
requestDataQuery(credentials:readOptions:resultQueue:completion)
.Note: If this is called on either a write-only contract or a contract which reads non-service data, this will return an error.
Declaration
Swift
public func readAccounts(resultQueue: DispatchQueue = .main, completion: @escaping (Result<AccountsInfo, SDKError>) -> Void)
Parameters
resultQueue
The dispatch queue which the completion block will be called on. Defaults to main dispatch queue.
completion
Block called upon completion containing either relevant account info, if successful, or an error
-
Fetches content for all the files limited by read options.
An attempt is made to fetch each requested file and the result of the attempt is passed back via the download handler. As download requests are asynchronous, the download handler may be called concurrently, so the handler implementation should allow for this.
If this function is called while files are being read, an error denoting this will be immediately returned in the completion block of this subsequent call and will not affect any current calls.
For reading data written by another contract, it may be necessary for force a new session by calling
requestDataQuery(credentials:readOptions:resultQueue:completion)
first (and waiting for completion).For service-based data sources, will also attempt to retrieve any new data directly from the services, in which case this completion handler will not be called until this synchronization has finished.
Alternatively, caller can manage reading files themselves by using the calls:
requestDataQuery()
,readFileList()
andreadFile()
Declaration
Swift
public func readAllFiles(credentials: Credentials, readOptions: ReadOptions?, resultQueue: DispatchQueue = .main, downloadHandler: @escaping (Result<File, SDKError>) -> Void, completion: @escaping (Result<(FileList, Credentials), SDKError>) -> Void)
Parameters
credentials
The existing credentials for the contract.
readOptions
Options to filter which data is read from sources for this session. Only used for read contracts.
resultQueue
The dispatch queue which the download handler and completion blocks will be called on. Defaults to main dispatch queue.
downloadHandler
Handler called after every file fetch attempt finishes. Either contains the file or an error if fetch failed
completion
Block called when fetching all files has completed. Contains final list of files (along with new or refreshed credentials) or an error if reading file list failed
-
Creates a session during which files can be read. This session is typically valid for 15 minutes. Once it has expired, a new session will be required to continue reading data.
For service-based data sources, will also attempt to retrieve any new data directly from the services.
Declaration
Swift
public func requestDataQuery(credentials: Credentials, readOptions: ReadOptions?, resultQueue: DispatchQueue = .main, completion: @escaping (Result<Credentials, SDKError>) -> Void)
Parameters
credentials
The existing credentials for the contract.
readOptions
Options to filter which data is read from sources for this session. Only used for read contracts.
resultQueue
The dispatch queue which the download handler and completion blocks will be called on. Defaults to main dispatch queue.
completion
Block called upon completion with new or refreshed credentials, or any errors encountered.
-
Retrieves a list of files contained within the user’s library.
Requires a valid session to have been created, either implicitly by adding a new service, or explicitly by calling
requestDataQuery(credentials:readOptions:resultQueue:completion)
.For service-based sources, it can take a while for new data to be added to user’s library (following a
requestDataQuery
call). Therefore caller should poll this call while data is being added to the library in case new files become available. Synchronization is complete whenfileList.status.state.isRunning
becomesfalse
.Declaration
Parameters
resultQueue
The dispatch queue which the download handler and completion blocks will be called on. Defaults to main dispatch queue.
completion
Block called upon completion with the list of files, or any errors encountered.
-
Retrieves the content of a specified file.
Requires a valid session to have been created, either implicitly by adding a new service, or explicitly by calling
requestDataQuery(credentials:readOptions:resultQueue:completion)
.Declaration
Parameters
fileId
The file’s identifier.
resultQueue
The dispatch queue which the download handler and completion blocks will be called on. Defaults to main dispatch queue.
completion
Block called upon completion with file, or any errors encountered.
-
Writes data to user’s library associated with configured contract
Declaration
Swift
public func write(data: Data, metadata: RawFileMetadata, credentials: Credentials, resultQueue: DispatchQueue = .main, completion: @escaping (Result<Credentials, SDKError>) -> Void)
Parameters
data
The data to be written
metadata
The metadata describing the data to be written. See
RawFileMetadataBuilder
for details on building the metadatacredentials
The existing credentials for the contract.
resultQueue
The dispatch queue which the completion block will be called on. Defaults to main dispatch queue.
completion
Block called when writing data has complete with new or refreshed credentials, or any errors encountered.
-
Deletes the user’s library associated with the configured contract.
Please note that if multiple contracts are linked to the same library, then
deleteUser
will also invalidate any credentials for those contracts.Declaration
Swift
public func deleteUser(credentials: Credentials, resultQueue: DispatchQueue = .main, completion: @escaping (SDKError?) -> Void)
Parameters
credentials
The existing credentials for the contract.
resultQueue
The dispatch queue which the completion block will be called on. Defaults to main dispatch queue.
completion
Block called on completion with any error encountered.
-
Get a list of possible services a user can add to their digi.me. If contract identifier is specified, then only those services relevant to the contract are retrieved, otherwise all services are retrieved.
Declaration
Swift
public func availableServices(contractId: String?, resultQueue: DispatchQueue = .main, completion: @escaping (Result<ServicesInfo, SDKError>) -> Void)
Parameters
contractId
The contract identifier for which relevant available services are retrieved. If
nil
then all services are retrieved.resultQueue
The dispatch queue which the completion block will be called on. Defaults to main dispatch queue.
completion
Block called upon completion with either the service list or any errors encountered
-
Clear cached data.
Declaration
Swift
public func clearCachedData(for contractId: String)
Parameters
contractId
The contract identifier for which relevant available service