PrivMX DOCS
Swift

Store Events

Events play a crucial role in modern applications, allowing them to instantly respond to changes in stored data. Monitoring and reacting to file and store-related events, such as the creation, modification, or deletion of files, is essential for maintaining up-to-date records, triggering workflows, and ensuring synchronization across various parts of the system.

Types of Events

Store events:

  • storeCreated - triggers when a new Store is created in your Context
  • storeDeleted - triggers when a Store is deleted from your Context
  • storeUpdated - triggers when a Store is updated in your Context
  • storeStatsChanged - triggers when a file is created or deleted from a Store

File events:

  • storeFileCreated - triggers when a file is uploaded to a Store
  • storeFileDeleted - triggers when a file is deleted from a Store
  • storeFileUpdated - triggers when a file is updated in a Store

Handling Store Events

Sample code on this page is based on the initial assumptions.

Before receiving Events, your application must first start an event loop and subscribe to specific events in the given scope. Afterwards you can setup a listener.

Here is an example of how to do it in your own project:

Swift

	let storeId = "STORE_ID"
	let fileId = "FILE_ID"
	
	Task{
		try? await endpointContainer?.startListening()
	}
	
	let registrationErrors = endpointSession?.registerCallbacksInBulk(
		[
			PMXEventCallbackRegistration(
				request: .store(
					eventType: privmx.endpoint.store.STORE_CREATE,
					selectorType: .Context,
					selectorId: CONTEXT_ID),
				group: "SOME_UNIQUE_IDENTIFIER",
				cb:{ eventData in
					// some actions when a new store created
				}),
			PMXEventCallbackRegistration(
				request: .store(
					eventType: privmx.endpoint.store.STORE_UPDATE,
					selectorType: .Context,
					selectorId: CONTEXT_ID),
				group: "SOME_UNIQUE_IDENTIFIER",
				cb:{ eventData in
					// some actions when a store is updated
				}),
			PMXEventCallbackRegistration(
				request: .store(
					eventType: privmx.endpoint.store.STORE_UPDATE,
					selectorType: .Container,
					selectorId: storeId),
				group: "SOME_UNIQUE_IDENTIFIER",
				cb:{ eventData in
					// some actions when a store is updated
				}),
			PMXEventCallbackRegistration(
				request: .store(
					eventType: privmx.endpoint.store.STORE_STATS,
					selectorType: .Context,
					selectorId: CONTEXT_ID),
				group: "SOME_UNIQUE_IDENTIFIER",
				cb:{ eventData in
					// some actions when a store's stats change
				}),
			PMXEventCallbackRegistration(
				request: .store(
					eventType: privmx.endpoint.store.STORE_STATS,
					selectorType: .Container,
					selectorId: storeId),
				group: "SOME_UNIQUE_IDENTIFIER",
				cb:{ eventData in
					// some actions when a store's stats change
				}),
			PMXEventCallbackRegistration(
				request: .store(
					eventType: privmx.endpoint.store.STORE_DELETE,
					selectorType: .Context,
					selectorId: CONTEXT_ID),
				group: "SOME_UNIQUE_IDENTIFIER",
				cb:{ eventData in
					// some actions when a store is deleted
				}),
			PMXEventCallbackRegistration(
				request: .store(
					eventType: privmx.endpoint.store.STORE_DELETE,
					selectorType: .Container,
					selectorId: storeId),
				group: "SOME_UNIQUE_IDENTIFIER",
				cb:{ eventData in
					// some actions when a store is deleted
				}),
			PMXEventCallbackRegistration(
				request: .store(
					eventType: privmx.endpoint.store.COLLECTION_CHANGE,
					selectorType: .Context,
					selectorId: CONTEXT_ID),
				group: "SOME_UNIQUE_IDENTIFIER",
				cb:{ eventData in
					// some actions when any store's contents change
				}),
			PMXEventCallbackRegistration(
				request: .store(
					eventType: privmx.endpoint.store.COLLECTION_CHANGE,
					selectorType: .Container,
					selectorId: storeId),
				group: "SOME_UNIQUE_IDENTIFIER",
				cb:{ eventData in
					// some actions when a particular store's contents change
				}),
			PMXEventCallbackRegistration(
				request: .store(
					eventType: privmx.endpoint.store.FILE_CREATE,
					selectorType: .Context,
					selectorId: CONTEXT_ID),
				group: "SOME_UNIQUE_IDENTIFIER",
				cb:{ eventData in
					// some actions on any new file
				}),
			PMXEventCallbackRegistration(
				request: .store(
					eventType: privmx.endpoint.store.FILE_CREATE,
					selectorType: .Container,
					selectorId: storeId),
				group: "SOME_UNIQUE_IDENTIFIER",
				cb:{ eventData in
					// some actions on new file in a particular store
				}),
			PMXEventCallbackRegistration(
				request: .store(
					eventType: privmx.endpoint.store.FILE_UPDATE,
					selectorType: .Context,
					selectorId: CONTEXT_ID),
				group: "SOME_UNIQUE_IDENTIFIER",
				cb:{ eventData in
					// some actions when any file is updated
				}),
			PMXEventCallbackRegistration(
				request: .store(
					eventType: privmx.endpoint.store.FILE_UPDATE,
					selectorType: .Container,
					selectorId: storeId),
				group: "SOME_UNIQUE_IDENTIFIER",
				cb:{ eventData in
					// some actions when a file in a particular store is updated
				}),
			PMXEventCallbackRegistration(
				request: .store(
					eventType: privmx.endpoint.store.FILE_UPDATE,
					selectorType: .Item,
					selectorId: fileId),
				group: "SOME_UNIQUE_IDENTIFIER",
				cb:{ eventData in
					// some actions when a particular file is updated
				}),
			
			PMXEventCallbackRegistration(
				request: .store(
					eventType: privmx.endpoint.store.FILE_DELETE,
					selectorType: .Context,
					selectorId: CONTEXT_ID),
				group: "SOME_UNIQUE_IDENTIFIER",
				cb:{ eventData in
					// some actions when any file is deleted
				}),
			
			PMXEventCallbackRegistration(
				request: .store(
					eventType: privmx.endpoint.store.FILE_DELETE,
					selectorType: .Container,
					selectorId: storeId),
				group: "SOME_UNIQUE_IDENTIFIER",
				cb:{ eventData in
					// some actions when a file in a particular store is deleted
				}),
			PMXEventCallbackRegistration(
				request: .store(
					eventType: privmx.endpoint.store.FILE_DELETE,
					selectorType: .Item,
					selectorId: fileId),
				group: "SOME_UNIQUE_IDENTIFIER",
				cb:{ eventData in
					// some actions when a particular file is deleted
				})
		])

We use cookies on our website. We use them to ensure proper functioning of the site and, if you agree, for purposes such as analytics, marketing, and targeting ads.

PrivMX Endpoint Swift v2.6

This package is not up to date with the core documentation. Some of the features you've seen described in other parts of the documentation might not be mentioned here. Those changes do not influence compatibility, however

On this page

Store Events | PrivMX Docs