SyncServer

public class SyncServer : NSObject

Synchronize files and app meta data with other instances of the same client app.

  • The singleton for this class.

    Declaration

    Swift

    public static let session: SyncServer
  • Declaration

    Swift

    public static let backgroundTest: SMPersistItemBool
  • Enable reporting of only events desired by the client app.

    Declaration

    Swift

    public var eventsDesired: EventDesired { get set }
  • The delegate enables operations such as file downloads & conflict resolution.

    Declaration

    Swift

    public weak var delegate: SyncServerDelegate! { get set }
  • Put a call to this in your AppDelegate or other place early in the launch sequence of your app.

    Declaration

    Swift

    public func appLaunchSetup(withServerURL serverURL: URL, cloudFolderName:String?, minimumServerVersion:ServerVersion? = nil, failoverMessageURL:URL? = nil)

    Parameters

    withServerURL

    URL for the SyncServerII server.

    cloudFolderName

    In the cloud storage service, the path of the directory/folder in which to put files. cloudFolderName is optional because it’s only needed for some of the cloud storage services (e.g., Google Drive).

    minimumServerVersion

    The minimum SyncServerII server version needed by your app. Leave nil if your app doesn’t have a specific server version requirement.

    failoverMessageURL

    Optional URL on which to do a GET for a message if the server fails, to show a message to the user.

  • For dealing with background uploading/downloading. Call this from the same named delegate method in your AppDelegate.

    Declaration

    Swift

    public func application(_ application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: @escaping () -> Void)
  • Enqueue a local immutable file for subsequent upload.

    Immutable files are assumed to not change (at least until after the upload has completed). This immutable characteristic is not enforced by this class but needs to be enforced by the caller of this class.

    This operation survives app launches, as long as the call itself completes.

    If there are contents with the same uuid, which have been enqueued for upload (file upload or appMetaData upload) but not yet sync‘ed, they will be replaced by this upload request. That is, if you want to do both a file upload and an appMetaData upload in the same sync, then set the SyncAttributes with the appMetaData, and use one of the file upload operations.

    This operation does not access the server, and thus runs quickly and synchronously.

    You can only set the fileGroupUUID (in the SyncAttributes) when the file is first uploaded.

    When uploading a file for the 2nd or more time (multi-version upload):

    1. the 2nd and following updates must have the same mimeType as the first version of the file.
    2. If the attr.appMetaData is given as nil, and an earlier version had non-nil appMetaData, then the nil appMetaData is ignored– i.e., the existing app meta data is not set to nil.

    The sharingGroupUUID (in the SyncAttributes) for a series of files up until a sync() operation must be the same. If you want to change to dealing with a different sharing group, you must call sync().

    A single file (a single fileUUID) can only be stored in a single sharingGroupUUID. It is an error to attempt to upload the same fileUUID to a different sharingGroupUUID.

    Warning: If you indicate that the mime type is text/plain, and you are using Google Drive and the text contains unusual characters, you may run into problems– e.g., downloading the files may fail.

    Declaration

    Swift

    public func uploadImmutable(localFile: SMRelativeLocalURL, withAttributes attr: SyncAttributes) throws

    Parameters

    localFile

    URL for the file to upload.

    withAttributes

    Attributes of the file to upload.

  • A copy of the file is made, and that is used for uploading. The caller can then change their original and it doesn’t affect the upload. The copy is removed after the upload completes. This operation proceeds like uploadImmutable otherwise.

    Declaration

    Swift

    public func uploadCopy(localFile: SMRelativeLocalURL, withAttributes attr: SyncAttributes) throws
  • Enqueue an upload of changed app meta data for an existing file.

    Like the other uploads above:

    1. This operation survives app launches, as long as the call itself completes,
    2. This operation does not access the server, and thus runs quickly and synchronously, and
    3. If there is a file with the same uuid, which has been enqueued for upload (file contents or appMetaData) but not yet sync‘ed, it will be replaced by this upload request.

    Declaration

    Swift

    public func uploadAppMetaData(attr: SyncAttributes) throws

    Parameters

    attr

    These attributes must have non-nil appMetaData.

  • This method enqueues an upload deletion operation. The operation persists across app launches. It is an error to try again later to upload, or delete the file referenced by this UUID. You can only delete files that are already known to the SyncServer (e.g., that you’ve uploaded).

    If there is a file with the same uuid, which has been enqueued for upload but not yet sync‘ed, it will be removed.

    This operation does not access the server, and thus runs quickly and synchronously.

    This operation undoes its work if it throws an error.

    Declaration

    Swift

    public func delete(fileWithUUID uuid: UUIDString) throws

    Parameters

    fileWithUUID

    The UUID of the file to delete.

  • As above, but you can give multiple UUIDs.

    Declaration

    Swift

    public func delete(filesWithUUIDs uuids: [UUIDString]) throws

    Parameters

    filesWithUUIDs

    The UUID of the files to delete.

  • Enqueue sharing group creation operation. The current queue of upload operations must be empty (e.g., you must have done a sync operation).

    Declaration

    Swift

    public func createSharingGroup(sharingGroupUUID: String, sharingGroupName: String? = nil) throws
  • Enqueue request to update the given sharing group. If there is a sharing group update operation queued already (and unsynced), it will be removed and this will replace that. I.e., multiple sharing group updates result in the last update being applied.

    Declaration

    Swift

    public func updateSharingGroup(sharingGroupUUID: String, newSharingGroupName: String) throws
  • Enqueue request to remove the current user from the given sharing group. Since this is removing the user from the sharing group: (a) The current queue of upload operations must be empty (e.g., you must have done a sync operation), and (b) you must do a sync() operation immediately after this call. I.e., it’s an error to queue further operations for the same sharing group.

    Declaration

    Swift

    public func removeFromSharingGroup(sharingGroupUUID: String) throws
  • Are there operation uploads pending? Pending uploads are those that were enqueued and committed with a sync. This includes file uploads, groups, and deletions.

    Declaration

    Swift

    public var uploadsPending: Bool { get }
  • The sharing groups that the user is currently a member of, and known to the server. syncNeeded in sharing groups will be non-nil.

    Declaration

    Swift

    public var sharingGroups: [SharingGroup] { get }
  • Operates in one of two modes:

    1) If you give a non-nil sharingGroupUUID, if no other sync is taking place, this will asynchronously do pending downloads, file uploads, and upload deletions for the given sharing group. If there is a sync currently taking place (for any sharing group), this closes the collection of uploads/deletions queued (if any) for the sharingGroupUUID, and will wait until after the current sync is done, and try again. Also synchronizes the sharingGroups property with the server.

    In this case you can also give reAttemptGoneDownloads = true, which will reattempt downloads for files previously marked as gone. See SyncAttributes.
    
    You can also give pushNotificationMessage in this case, which will be sent to all other users in the sharing group as a push notification.
    

    2) If you give a nil-sharingGroupUUID, only synchronizes the sharingGroups property. Doesn’t do pending downloads or uploads etc. And doesn’t close a collection of queued operations (reAttemptGoneDownloads ignored in this case).

    If a stopSync is currently pending, then this call will be ignored.

    If there is no network connection, the sync will be attempted next time the app is in the foreground and there is a network connection.

    Non-blocking in all cases.

    Declaration

    Swift

    public func sync(sharingGroupUUID: String? = nil, reAttemptGoneDownloads: Bool = false, pushNotificationMessage: String? = nil) throws
  • Is there a sync operation in progress?

    Declaration

    Swift

    public var isSyncing: Bool { get }
  • Stop an ongoing sync operation. This will stop the operation at the next natural stopping point. E.g., after a next download completes. No effect if no ongoing sync operation. Any delayed sync(s) are cancelled.

    Declaration

    Swift

    public func stopSync()
  • Operates synchronously and quickly. A file must have already been uploaded (or downloaded) for you to be able to get its attributes. It is an error to call this for a file UUID that doesn’t yet exist, or for one that has already been deleted.

    Declaration

    Swift

    public func getAttributes(forFileUUID fileUUID: String) throws -> SyncAttributes

    Parameters

    forFileUUID

    The UUID of the file to get attributes for.

  • Use this to request the re-download of a file, on a subsequent sync with the relevant sharing group UUID. E.g., for when a file could not be read due to some kind of corruption. Requests to download a file that is already gone are ignored. Use the reAttemptGoneDownloads flag of the sync method instead. Note that this is a request for download because normal sync operations can take priority. E.g., it is possible that the file might be deleted by a server download deletion before this request gets a chance to operate.

    Declaration

    Swift

    public func requestDownload(forFileUUID fileUUID: String) throws
  • The type of reset to perform with a call to reset.

    See more

    Declaration

    Swift

    public enum ResetType
  • Does a reset of local (not server) tracking data.

    Doesn’t sign the user out or require that the user is signed in.

    This method may only be called when the client is not doing any sync operations.

    Declaration

    Swift

    public func reset(type: ResetType) throws

    Parameters

    type

    type of reset to perform.

  • Logs information about all tracking internal meta data.

    Declaration

    Swift

    public func logAllTracking(completion: (()->())? = nil)
  • Return result from localConsistencyCheck.

    See more

    Declaration

    Swift

    public struct LocalConsistencyResults
  • Performs a similar operation to a file system consistency or integrity check. Only operates if not currently synchronizing. Suitable for running at app startup.

    Declaration

    Swift

    public func localConsistencyCheck(clientFiles: [UUIDString]) throws -> LocalConsistencyResults?

    Parameters

    clientFiles

    UUID’s of files known to the client.

  • This is intended for development/debug only. This enables you do a consistency check between your local files and SyncServer meta data. Does a sync first to ensure files are synchronized.

    Declaration

    Swift

    public func consistencyCheck(sharingGroupUUID: String, localFiles:[UUIDString], repair:Bool = false, completion:((Error?)->())?) throws