OfflineDataServiceAsync
@available(swift 5.5)
open class OfflineDataServiceAsync : DataServiceAsync
An specialization of DataService where the provider is a DataSyncProvider, using the async/await style of asynchronous operations.
-
Construct an offline data service using an offline provider.
Declaration
Swift
public init(provider: DataSyncProvider)Parameters
providerOffline provider.
-
(Asynchronous) Cancel any download(s) that are currently in progress.
See also
download.Declaration
Swift
open func cancelDownload() async throws -
(Asynchronous) Cancel the specifed pending requests.
See also
getQueuedRequests,getFailedRequests.Declaration
Swift
open func cancelPendingRequests(_ requests: PendingRequestList? = nil) async throwsParameters
requestsPending requests to be cancelled. If not specified (or null), then all pending requests will be cancelled. If empty, then no pending requests will be cancelled.
-
(Asynchronous) Cancel any upload(s) that are currently in progress.
See also
upload.Declaration
Swift
open func cancelUpload() async throws -
(Asynchronous) Clear the
syncProvider, destroying the local database. This does not communicate with the backend system.Declaration
Swift
open func clear() async throws -
(Asynchronous) Close the
syncProvider, disconnecting from the local database. This does not communicate with the backend system.Declaration
Swift
open func close() async throws -
(Asynchronous) Create a persistent query to specify criteria for downloading entities for an entity set. This query is persisted across application restarts. Multiple download queries can be defined for the same entity set (e.g. with different filters).
See also
DataQuery.entitySet,deleteDownloadQuery,getDownloadQuery,getDownloadQueries,OfflineDataService.downloadQueriesCanOverlap,OfflineDataService.noDefaultEntityDownload,OfflineDataService.noDefaultStreamDownload.Declaration
Swift
open func createDownloadQuery(name: String, query: DataQuery, streams: Bool = false) async throwsParameters
nameQuery name. Must be unique.
queryData query. Use
DataQuery.fromto specify the query’s entity set.streamsIf
true, then enable downloading of associated streams. Defaults tofalse, but may be overridden byEntitySet.downloadStreamsByDefault. -
(Asynchronous) Delete a persistent query previously created by
createDownloadQuery, along with any previously downloaded associated entities. Note: if there is a large number of previously downloaded associated entities, deletion of the download query might be time-consuming. Consider invoking this method in a background thread to avoid blocking the application’s user interface thread.Declaration
Swift
open func deleteDownloadQuery(name: String) async throwsParameters
nameQuery name.
-
(Asynchronous) Download backend data changes into the local database.
Declaration
Swift
open func download(groups: StringList? = nil, options: SyncOptions? = nil) async throwsParameters
groupsIf null or empty, then data will be downloaded from all entity sets. If non-empty, then it specifies groups to be downloaded.
optionsDownload options, including cancellation token and progress listener.
-
Configure one or more entity sets to be downloaded in a named group, by setting
EntitySet.downloadGroupfor all of the specified entity sets. Download groups are used to limit (select) the entity sets to be downloaded. Note: this function does not actually perform the download. It simply configures entity sets for later download calls.See also
download(groupsparameter).Declaration
Swift
open func downloadInGroup(_ group: String, _ entitySets: EntitySet...)Parameters
groupDownload group name.
rest_entitySetsA list of entity sets whose
EntitySet.downloadGroupwill be set. -
Configure one or more entity sets to be downloaded in a numbered phase and specified mode, by setting
EntitySet.downloadPhaseandEntitySet.downloadModefor all of the specified entity sets. Also theEntitySet.downloadOrderfor the respective entity sets will be set from 1 to the number of entity sets, in the order indicated by theentitySetsparameter. Download phases are used to order (sort) the entity sets to be downloaded. Note: this function does not actually perform the download. It simply configures entity sets for later download calls.See also
download.Declaration
Swift
open func downloadInPhase(_ phase: Int, _ mode: DownloadMode, _ entitySets: EntitySet...)Parameters
phaseDownload phase number, which should be greater than zero. If a zero or negative value is provided, then download will be disabled for the specified entity sets.
modeDownload mode.
rest_entitySetsA list of entity sets whose
EntitySet.downloadPhaseandEntitySet.downloadOrderwill be set. If this list is empty, all entity sets will be configured with the specified phase and mode. -
(Asynchronous) Retrieve all of the persistent queries previously created by
createDownloadQueryfor a specified entity set.Declaration
Swift
open func downloadQueries(from: EntitySet? = nil) async throws -> DownloadQueryListParameters
fromEntity set. If not specified, then download queries for all entity sets are returned.
Return Value
List of matching download queries.
-
Configure one or more entity sets to allow overlapping results when multiple download queries are used per entity set. By default (for optimal performance), it is assumed that multiple download queries for the same entity set will have non-overlapping query results, e.g. by the appropriate use of
DataQuery.filterfor each download query. Allowing for overlapping results requires the provider to track downloaded keys, but ensures that deleting a download query will result in deletion of downloaded entities only when they are not related to one or more other download queries.Declaration
Swift
open func downloadQueriesCanOverlap(_ entitySets: EntitySet...)Parameters
rest_entitySetsA list of entity sets whose
downloadQueriesCanOverlapproperty will be set totrue. If this list is empty, all entity sets will be configured to allow overlapping download query results. -
(Asynchronous) Retrieve a persistent query previously created by
createDownloadQuery.Declaration
Swift
open func downloadQuery(name: String) async throws -> DownloadQuery?Parameters
nameQuery name.
Return Value
The download query, or
nilif no query exists with the specified name. -
Configure one or more entity sets to enable downloads without delta links. If this property is set to
true, then download requests to the backend service are expected to return all relevant data (as opposed to returning just changed data), in which case the effective changes will be determined on the client side, and applied to the local database as needed. For large data sets, client-side change determination can result in high client-side CPU, memory, and network utilization. It is recommended to use delta-enabled backend services when working with large data sets, instead of setting this property totrue. If you are considering setting this property totrue, please evaluate the client-side resource utilization, and consider the alternative option of delta-enabling the backend system.See also
EntitySet.downloadWithoutDeltaLinks.Declaration
Swift
open func downloadWithoutDeltaLinks(_ entitySets: EntitySet...)Parameters
rest_entitySetsA list of entity sets whose
downloadWithoutDeltaLinksproperty will be set totrue. If this list is empty, all entity sets will be configured to enable downloads without delta links. -
(Asynchronous) @return a list of the synchronization events since the local database was created.
See also
SyncEvent.eventID,SyncEvent.type, andSyncEvent.time(psuedo-properties that can be referenced by the query for filtering and ordering).Declaration
Swift
open func eventHistory(matching query: DataQuery?) async throws -> SyncEventListParameters
queryIf specified, then
DataQuery.queryFilterwill be used for event filtering andDataQuery.sortItemswill be used for result ordering. If not specified (or null), all synchronization events will be returned. -
(Asynchronous) @return a list of the failed pending requests in the local database (matching the
query, if specified).Declaration
Swift
open func failedRequests(matching query: DataQuery? = nil, headers: HTTPHeaders? = nil, options: RequestOptions? = nil) async throws -> PendingRequestListParameters
queryIf specified, then
DataQuery.entitySetandDataQuery.queryFilterwill be used for request filtering andDataQuery.sortItemswill be used for result ordering. If not specified (or null), all failed requests will be returned.headersIf specified, then the returned pending requests will be further filtered to include only those with matching headers.
optionsIf specified, then the returned pending requests will be further filtered to include only those with matching options (
RequestOptions.changeSet,RequestOptions.customTag,RequestOptions.uploadGroup).Return Value
List of failed requests.
-
Declaration
Swift
open func hasFailedRequests(matching query: DataQuery? = nil, headers: HTTPHeaders? = nil, options: RequestOptions? = nil) throws -> BoolParameters
queryIf specified, then
DataQuery.entitySetandDataQuery.queryFilterwill be used for request filtering.headersIf specified, then the returned pending requests will be further filtered to include only those with matching headers.
optionsIf specified, then the returned pending requests will be further filtered to include only those with matching options (
RequestOptions.changeSet,RequestOptions.customTag,RequestOptions.uploadGroup).Return Value
trueif there are any failed requests in the local database (matching thequery, if specified). This includes requests that have been sent to the backend system, but which failed to execute successfully. -
Declaration
Swift
open func hasInitialData() throws -> BoolReturn Value
trueifdownloadhas been explicitly or implicitly called (byopen) to obtain initial data. -
Determine if this provider has detected metadata changes (during a previous
download) that require re-downloading of previously downloaded entity sets. For example, if an additional property has been added to an entity type, and the relevent data needs to be re-downloaded to obtain values for the added property. Note: When metadata changes, the changes might not take full effect until an application restart.See also
metadataListener.Declaration
Swift
open func hasMetadataChanges() throws -> BoolReturn Value
trueif this provider has detected metadata changes. -
Declaration
Swift
open func hasPendingDownload() throws -> BoolReturn Value
trueif adownloadis currently in progress or if the previous download did not terminate normally (i.e. it failed or was cancelled). -
Declaration
Swift
open func hasPendingUpload() throws -> BoolReturn Value
trueif anuploadis currently in progress or if the previous upload did not terminate normally (i.e. it failed or was cancelled). -
Declaration
Swift
open func hasQueuedRequests(matching query: DataQuery? = nil, headers: HTTPHeaders? = nil, options: RequestOptions? = nil) throws -> BoolParameters
queryIf specified, then
DataQuery.entitySetandDataQuery.queryFilterwill be used for request filtering.headersIf specified, then the returned pending requests will be further filtered to include only those with matching headers.
optionsIf specified, then the returned pending requests will be further filtered to include only those with matching options (
RequestOptions.changeSet,RequestOptions.customTag,RequestOptions.uploadGroup).Return Value
trueif there are any queued requests in the local database (matching thequery, if specified). -
Declaration
Swift
open func lastDownloadTime() throws -> GlobalDateTime?Return Value
Date and time for the last
downloadrequest. -
Declaration
Swift
open func lastUploadTime() throws -> GlobalDateTime?Return Value
Date and time for the last
uploadrequest. -
Load previously saved download time estimates from
file.Declaration
Swift
open func loadTimeEstimates(file: String, mustExist: Bool = false) throwsParameters
fileTime estimates file.
mustExistSpecify
trueif the file must exist. Existing in-memory time estimates remain unchanged if this parameter isfalseand the file does not exist. Defaults tofalse. -
Metadata change listener. When metadata changes, the changes might not take full effect until an application restart. It is therefore advisable to restart the application process when the metadata has changed.
Declaration
Swift
open var metadataListener: MetadataListener? { get set } -
Disable download-by-default for the entities of an entity set. This indicates that entity data should only be downloaded if explicitly enabled by use of
createDownloadQuery.See also
EntitySet.downloadEntitiesByDefault.Declaration
Swift
open func noDefaultEntityDownload(_ entitySets: EntitySet...)Parameters
rest_entitySetsA list of entity sets whose
downloadEntitiesByDefaultproperty will be set tofalse. If this list is empty, all entity sets will be configured to disable default entity download. -
Disable download-by-default for the streams of an entity set.
See also
EntitySet.downloadStreamsByDefault.Declaration
Swift
open func noDefaultStreamDownload(_ entitySets: EntitySet...)Parameters
rest_entitySetsA list of entity sets whose
downloadStreamsByDefaultproperty will be set tofalse. If this list is empty, all entity sets will be configured to disable default stream download. -
The online provider supporting this data service.
Declaration
Swift
open var onlineProvider: OnlineODataProvider { get } -
(Asynchronous) Open the
syncProvider, performing any necessary initialization such as creation of the local database. Depending on the provider implementation, the first call to open might (or might not) communicate with the backend system. IfhasInitialDatareturnsfalseafter callingopen, thendownloadmust be explicitly called to obtain initial data. IfhasInitialDatareturnstrueafter callingopen, then initial data has already been obtained from the backend system.Declaration
Swift
open func open() async throws -
In a multiple user scenario, when a new user starts using the application on a mobile device, it might have pending requests in the local database that need to be uploaded using the previous user’s identity. This function can be called before
openis called to determine whether special action is needed. Callingopenwhen there is a known previous user might result inuploadand/ordownloadbeing called byopen.Declaration
Swift
open func previousUser() throws -> String?Return Value
the previous user of the local database (if available).
-
Progress listener for
downloadandupload.Declaration
Swift
open var progressListener: ProgressListener? { get set } -
(Asynchronous) @return a list of the queued pending requests in the local database (matching the
query, if specified). This includes requests that have never been sent to the backend system, as well as requests that were previously sent but which failed.Declaration
Swift
open func queuedRequests(matching query: DataQuery? = nil, headers: HTTPHeaders? = nil, options: RequestOptions? = nil) async throws -> PendingRequestListParameters
queryIf specified, then
DataQuery.entitySetandDataQuery.queryFilterwill be used for request filtering andDataQuery.sortItemswill be used for result ordering. If not specified (or null), all queued requests will be returned.headersIf specified, then the returned pending requests will be further filtered to include only those with matching headers.
optionsIf specified, then the returned pending requests will be further filtered to include only those with matching options (
RequestOptions.changeSet,RequestOptions.customTag,RequestOptions.uploadGroup).Return Value
List of queued requests.
-
Save download time estimates to
file. Should be called after a download operation.Declaration
Swift
open func saveTimeEstimates(file: String) throwsParameters
fileTime estimates file.
-
Service options for the associated online provider.
Declaration
Swift
open var serviceOptions: ServiceOptions { get } -
The synchronization provider supporting this data service.
Declaration
Swift
open var syncProvider: DataSyncProvider { get } -
(Asynchronous) Undo all pending (local) changes for
entities, so they will not be subsequently uploaded.Declaration
Swift
open func undoPendingChanges(for entities: EntityValueOrList) async throwsParameters
entitiesAn
EntityValueorEntityValueListwhose pending changes will be undone. -
(Asynchronous) Upload local pending changes to the backend OData service.
Declaration
Swift
open func upload(groups: StringList? = nil, options: SyncOptions? = nil) async throwsParameters
groupsIf null or empty, then data will be uploaded from all entity sets. If non-empty, then it specifies groups to be uploaded.
optionsUpload options, including cancellation token and progress listener.
-
(Asynchronous) Upload a copy of the local database file (or files) to the backend server (or an intermediary server) for diagnostic purposes. Note: if the local database is encrypted, and
encryptionKeyis null, this operation might fail (depending on the provider). Note: if the local database is not encrypted, andencryptionKeyis non-null, this operation might fail (depending on the provider).Declaration
Swift
open func uploadDatabaseFile(encryptionKey: String? = nil, note: String? = nil, options: SyncOptions? = nil) async throwsParameters
encryptionKeyEncryption key for the uploaded database, which may differ from the encryption key of the local database (if any).
noteAssociated note for trusted users who have access to uploaded database files for diagnostic purposes.
optionsUpload options, including cancellation token and progress listener.