QtDataSync  4.2.0
A simple offline-first synchronisation framework, to synchronize data of Qt applications between devices
Public Types | Public Slots | Signals | Public Member Functions | Static Public Member Functions | Protected Member Functions | Properties | List of all members
QtDataSync::IosSyncDelegate Class Reference

A helper class to perform background synchronization on Ios. More...

#include <iossyncdelegate.h>

+ Inheritance diagram for QtDataSync::IosSyncDelegate:

Public Types

enum  SyncResult { SyncResult::NewData, SyncResult::NoData, SyncResult::Error }
 The possible results of a synchronization attempt. More...
 

Public Slots

void setInterval (qint64 interval)
 WRITE accessor for IosSyncDelegate::interval.
 
void setEnabled (bool enabled)
 WRITE accessor for IosSyncDelegate::enabled.
 
void setWaitFullSync (bool waitFullSync)
 WRITE accessor for IosSyncDelegate::waitFullSync.
 

Signals

void intervalChanged (qint64 interval, QPrivateSignal)
 NOTIFY accessor for IosSyncDelegate::interval.
 
void enabledChanged (bool enabled, QPrivateSignal)
 NOTIFY accessor for IosSyncDelegate::enabled.
 
void waitFullSyncChanged (bool waitFullSync, QPrivateSignal)
 NOTIFY accessor for IosSyncDelegate::waitFullSync.
 

Public Member Functions

 IosSyncDelegate (QObject *parent=nullptr)
 Default constructor.
 
 IosSyncDelegate (QSettings *settings, QObject *parent=nullptr)
 Default constructor with settings to use for state restoration.
 
qint64 interval () const
 READ accessor for IosSyncDelegate::interval.
 
std::chrono::minutes intervalMinutes () const
 READ accessor for IosSyncDelegate::interval.
 
bool isEnabled () const
 READ accessor for IosSyncDelegate::enabled.
 
bool waitFullSync () const
 READ accessor for IosSyncDelegate::waitFullSync.
 
virtual bool persistState () const
 READ accessor for IosSyncDelegate::persistState.
 
template<typename TRep , typename TPeriod >
void setInterval (const std::chrono::duration< TRep, TPeriod > &interval)
 WRITE accessor for IosSyncDelegate::interval.
 
void setInterval (std::chrono::minutes interval)
 WRITE accessor for IosSyncDelegate::interval.
 
- Public Member Functions inherited from QObject
virtual const QMetaObjectmetaObject () const const
 
virtual void * qt_metacast (const char *)
 
virtual int qt_metacall (QMetaObject::Call, int, void **)
 
 QObject (QObject *parent)
 
virtual bool event (QEvent *e)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
QString objectName () const const
 
void setObjectName (const QString &name)
 
bool isWidgetType () const const
 
bool isWindowType () const const
 
bool signalsBlocked () const const
 
bool blockSignals (bool block)
 
QThreadthread () const const
 
void moveToThread (QThread *targetThread)
 
int startTimer (int interval, Qt::TimerType timerType)
 
int startTimer (std::chrono::milliseconds time, Qt::TimerType timerType)
 
void killTimer (int id)
 
findChild (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegExp &regExp, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
 
const QObjectList & children () const const
 
void setParent (QObject *parent)
 
void installEventFilter (QObject *filterObj)
 
void removeEventFilter (QObject *obj)
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
 
bool disconnect (const QObject *receiver, const char *method) const const
 
void dumpObjectTree ()
 
void dumpObjectInfo ()
 
void dumpObjectTree () const const
 
void dumpObjectInfo () const const
 
bool setProperty (const char *name, const QVariant &value)
 
QVariant property (const char *name) const const
 
QList< QByteArraydynamicPropertyNames () const const
 
void destroyed (QObject *obj)
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const const
 
bool inherits (const char *className) const const
 
void deleteLater ()
 

Static Public Member Functions

static void init (IosSyncDelegate *delegate=nullptr)
 Registers a sync delegate to let it perform synchronization if needed. More...
 
static IosSyncDelegatecurrentDelegate ()
 Returns the currently registered sync delegate. More...
 
- Static Public Member Functions inherited from QObject
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 

Protected Member Functions

virtual QString setupName () const
 Returns the name of the setup to be synchronized. More...
 
virtual void prepareSetup (Setup &setup)
 Prepares the setup to be synchronized. More...
 
virtual SyncResult onSyncCompleted (SyncManager::SyncState state)
 Is called by the service as soon the the synchronization has been completed. More...
 
virtual void performSync (std::function< void(QtDataSync::IosSyncDelegate::SyncResult)> callback)
 Is called by Ios to start the background synchronization. More...
 
- Protected Member Functions inherited from QObject
QObjectsender () const const
 
int senderSignalIndex () const const
 
int receivers (const char *signal) const const
 
bool isSignalConnected (const QMetaMethod &signal) const const
 
virtual void timerEvent (QTimerEvent *event)
 
virtual void childEvent (QChildEvent *event)
 
virtual void customEvent (QEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 

Properties

qint64 interval
 The interval in minutes between synchronizations. More...
 
bool enabled
 Specify if background synchronization is enabled or not. More...
 
bool waitFullSync
 Specify whether the service should wait for a full synchronization or only the download. More...
 
bool persistState
 Persist the state of properties so that on a restart of the application they can be restored. More...
 
- Properties inherited from QObject
 objectName
 

Detailed Description

A helper class to perform background synchronization on Ios.

This class is part of the QtDataSyncIos module, which is only available on the ios platform. It can be used to configure and run background synchronization so that your application is able to update it's internal data periodically in the background, even if your app is not actively used.

Warning
This class alone is not sufficient to make this possible. You will also have to correctly set up the Info.plist and other things. Have a look at the Ios Background synchronization to learn how to add background synchronization to your project.
See also
Ios Background synchronization, AndroidSyncControl, AndroidBackgroundService

Definition at line 20 of file iossyncdelegate.h.

Member Enumeration Documentation

◆ SyncResult

The possible results of a synchronization attempt.

Enumerator
NewData 

Synchronization was successful and new data was downloaded.

NoData 

Synchronization was successful but no new data was downloaded.

Error 

Synchronization failed.

Definition at line 36 of file iossyncdelegate.h.

Member Function Documentation

◆ currentDelegate()

QtDataSync::IosSyncDelegate::currentDelegate ( )
static

Returns the currently registered sync delegate.

Returns
The delegate currently set via init() or nullptr, if no delegate was set
See also
IosSyncDelegate::init

◆ init()

QtDataSync::IosSyncDelegate::init ( IosSyncDelegate delegate = nullptr)
static

Registers a sync delegate to let it perform synchronization if needed.

Parameters
delegateThe delegate to be set as sync delegate

You must call this method after creating the core app (but before executing it) to register a delegate as "active" delegate. This delegate will then control whether sync is enabled and handle the sync requests if your application is in the background.

Note
If persistState is true (the default), the init method will also restore the previously persisted state
See also
IosSyncDelegate::persistState, IosSyncDelegate::currentDelegate

◆ onSyncCompleted()

QtDataSync::IosSyncDelegate::onSyncCompleted ( SyncManager::SyncState  state)
protectedvirtual

Is called by the service as soon the the synchronization has been completed.

Parameters
stateThe state in which the synchronization finished
Returns
A sync result to tell the operating system how the synchronization finished

This method is called as soon as the datasync instance has finished the data synchronization. You can override it to perform additional operations with the data before quitting the service.

The default implementation only returns a sync result based on the sync state. You must do the same in your implementation. If you do not want to return synchronously, you must override the performSync() method instead.

Possible states that are typically passed to the method can be:

  • Uploading (only if waitFullSync is set to false)
  • Synchronized
  • Error
  • Disconnected

The default return value mapping is this method does is:

SyncState SyncResult
Downloading NewData
Uploading NewData
Synchronized NewData
Disconnected NoData
Error Error
See also
IosSyncDelegate::waitFullSync, IosSyncDelegate::performSync

◆ performSync()

QtDataSync::IosSyncDelegate::performSync ( std::function< void(QtDataSync::IosSyncDelegate::SyncResult)>  callback)
protectedvirtual

Is called by Ios to start the background synchronization.

Parameters
callbackA callback to be called with the sync result once the sync is done

This method is called by the operating system and contains the actual code to synchronize the data. If you want to reimplement this method, you should always call the base implementation as well to make shure synchronization works as expected.

In case you want to override this method to allow asynchronous sync result handling, you can use the following pattern. Simpyl impelement onSyncCompleted() as usual, but always return NewData (ignored). Instead add a signal with the SyncResult as parameter and emit this once the async sync operation has finished. Now implement this method and call the base implementation as usual, but pass an empty, self constructed callback to it that does nothing. Instead connect the actual callback to the previously declared signal (before calling the base impl.)

See also
IosSyncDelegate::onSyncCompleted

◆ prepareSetup()

QtDataSync::IosSyncDelegate::prepareSetup ( Setup setup)
protectedvirtual

Prepares the setup to be synchronized.

Parameters
setupThe setup to be prepared

You should override this method to configure the setup before creation (i.e. set properties on it). The default implementation does nothing.

See also
QtDataSync::Setup, IosSyncDelegate::setupName

◆ setupName()

QtDataSync::IosSyncDelegate::setupName ( ) const
protectedvirtual

Returns the name of the setup to be synchronized.

Returns
The name of the setup

The default implementation returns QtDataSync::DefaultSetup. You can override the method if you need the delegate to create the setup under a different name.

See also
QtDataSync::DefaultSetup, IosSyncDelegate::prepareSetup

Property Documentation

◆ enabled

QtDataSync::IosSyncDelegate::enabled
readwrite

Specify if background synchronization is enabled or not.

Default: false

These property directly communicates with the OS and schedules (or unschedules) the task to run the sync task. This means you must always set the interval first before enabling a task.

Accessors
READisEnabled()
WRITEsetEnabled()
NOTIFYenabledChanged()
Note
if persistState is enabled, this property is persisted
See also
IosSyncDelegate::interval, IosSyncDelegate::persistState

Definition at line 27 of file iossyncdelegate.h.

◆ interval

QtDataSync::IosSyncDelegate::interval
readwrite

The interval in minutes between synchronizations.

Default: 60 (minutes)

This value is passed to the operating system to schedule the background synchronization. There is no guarantee of exact delivery of those background synchronizations. For ios, this is only a minimal wait time, i.e. it is guaranteed that the synchronization will not be started before that time has passed.

Note
Due to the stupidity of Ios, this means sometimes the system won't even run the sync task in days, even though you specify an interval of an hour or less. There is nothing that can be done here, as you are fully at the mercy of apples proprietary optimization logic.
Accessors
READinterval()
READintervalMinutes()
WRITEsetInterval()
NOTIFYintervalChanged()
Note
if persistState is enabled, this property is persisted
See also
IosSyncDelegate::enabled, IosSyncDelegate::persistState

Definition at line 25 of file iossyncdelegate.h.

◆ persistState

QtDataSync::IosSyncDelegate::persistState
read

Persist the state of properties so that on a restart of the application they can be restored.

Default: true

If set to true, the delegate will store it's current state whenver the interval or the enabled properties are changed. The that will be automatically reloaded when passed to init().

For the default implementation of the delegate, persistance is always enabled. You can override this method in a custom class to deactivate it.

Properties that are stored are:

Accessors
READpersistState()
CONSTANT
See also
IosSyncDelegate::init, IosSyncDelegate::enabled, IosSyncDelegate::interval, IosSyncDelegate::waitFullSync

Definition at line 32 of file iossyncdelegate.h.

◆ waitFullSync

QtDataSync::IosSyncDelegate::waitFullSync
readwrite

Specify whether the service should wait for a full synchronization or only the download.

Default: true

If set to true, the delegate will internally call SyncManager::runOnSynchronized() with the onSyncCompleted() as handler. If disable, SyncManager::runOnDownloaded() is used instead. Check the documentation of these two methods.

Accessors
READwaitFullSync()
WRITEsetWaitFullSync()
NOTIFYwaitFullSyncChanged()
Note
if persistState is enabled, this property is persisted
See also
IosSyncDelegate::onSyncCompleted, SyncManager::runOnSynchronized, SyncManager::runOnDownloaded, IosSyncDelegate::persistState

Definition at line 30 of file iossyncdelegate.h.


The documentation for this class was generated from the following files: