PrivMX DOCS
Swift

Overview

Working with Events.

Events enable your application to react dynamically to changes within user context.

These events are triggered automatically when a relevant change occurs. You can subscribe to them by registering event listeners. This allows you to respond to changes as they happen in real-time.

Caveats

  • All callbacks are related to the connection on which they were registered.
  • Calling endpointContainer.stopListening() does not delete event listeners.
  • Disconnecting deletes all event listeners related to the connection.

Quick Start

Start the event loop:

Task{
 	try? await endpointContainer?.startListening()
 }

Add event listener for StoreFileCreatedEvent; the group parameter is used for removing callbacks.

let storeId = "STORE_ID"
try? endpointSession?.registerCallback(
	for: .init(
		request: .store(
            eventType: privmx.endpoint.store.FILE_CREATE,
            selectorType: PMXEventSelectorType.Context,
            selectorId: CONTEXT_ID),
		group: "some_group"){
	        eventData in
            // some actions to take
        }
)

Remove the event listener when no longer needed:

try? endpointContainer?
    .getEndpoint(endpointId)?
    .clearCallbacks(in: "some_group")

Unregister Callbacks

Unregister callbacks in specific group:

try? endpointContainer?
			.getEndpoint(endpointId)?
			.clearCallbacks(in: "some_group")

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

On this page