API reference

The complete API reference for the Knock Swift SDK.

In this section, you'll find the documentation for the classes and methods available in the Swift SDK.

Knock

The top-level Knock class. Create an authenticated Knock client instance for interacting with Knock.

Params

publishableKeystring*The public API key for the Knock environment.
userIdstring*The user ID to make requests against.
userTokenstring (optional)A signed user token, required when enhanced security mode is enabled on the environment.
hostnamestring (optional)Optional hostname to configure which Knock endpoint to make requests against.

Example


publishableKey

Returns the publishable key set on the client.

Returns: string


userId

Returns the userId set.

Returns: string


userToken

Returns the userToken set.

Returns: string


getUser

Returns the current user's profile stored in Knock.

Returns

Result<User, Error>


updateUser

Updates the current user's profile in Knock.

Params

userUserProperties to update on the current user

Returns

Result<User, Error>


getAllUserPreferences

Returns all of the preference sets for the current user.

Returns

Result<[PreferenceSet], Error>


getUserPreferences

Returns a single preference set for the current user, specified by the preferenceId. For the default preference set, set the preferenceId to be default.

Params

preferenceIdstringThe ID of the preference set to retrieve

Returns

Result<PreferenceSet, Error>


setUserPreferences

Updates the preference set specified by the preferenceId with the new preferenceSet.

Params

preferenceIdstringThe ID of the preference set
preferenceSetPreferenceSetThe preferences to update for the preference set

Returns

Result<PreferenceSet, Error>


getUserChannelData

Returns the channel data for the current user on the channel specified with channelId.

Params

channelIdstringThe channel ID to get channel data for

Returns

Result<ChannelData, Error>


updateUserChannelData

Updates the channel data for the current user on the channel specified with channelId.

Params

channelIdstringThe channel ID to update the channel data for
dataanyThe data to update for the channel data

Returns

Result<ChannelData, Error>


registerTokenForAPNS

A convenience method for getting and setting channel data for an APNS channel for the current user.

Params

channelIdstringThe channel ID to update the channel data for
tokenData | stringThe device token to set for

Returns

Result<ChannelData, Error>


getMessage

Returns information about a single message specified by the messageId.

Params

messageIdstringThe ID of the message to retrieve

Returns

Result<KnockMessage, Error>


updateMessageStatus

Updates the status of a single message specified by the message or messageId.

Params

messageIdstringThe ID of the message to update
messageKnockMessageA Knock message to update
statusKnockMessageStatusUpdateTypeThe status to set on the message

Returns

Result<KnockMessage, Error>


deleteMessageStatus

Removes the update of a single message status specified by the message or messageId.

Params

messageIdstringThe ID of the message to update
messageKnockMessageA Knock message to update
statusKnockMessageStatusUpdateTypeThe status to set on the message

Returns

Result<KnockMessage, Error>


batchUpdateStatuses

Updates up to 50 messages with the given status in a single request specified by messageIds or messages.

Params

messageIdsstring[]A list of message IDs
messageKnockMessage[]A list of messages
statusKnockMessageStatusBatchUpdateTypeThe status to set on the messages

Returns

Result<[KnockMessage], Error>


Knock.FeedManager

Creates a new instance of a FeedManager for interacting with a user's in-app notification feed.

Params

clientKnockThe instance of a Knock client to use to make requests.
feedIdstringThe UUID of the in-app feed channel ID.
optionsFeedClientOptionsFeed options to apply as defaults.

Example


connectToFeed

Connects the feed instance to the real-time socket so that any new items published to the feed are received over the websocket.

Params

optionsFeedClientOptions*Feed options to apply. Will override any options specified in the FeedManager constructor.

Returns

Void


disconnectFromFeed

Disconnects a connected real-time instance.

Returns

Void


on

Binds an event listener for incoming web socket events. Must have called connectToFeed first.

eventNamestring*The event name to listen for. Currently only `new-message` is supported.

Returns

Void

Example


getUserFeedContent

Retrieves the user's feed content for the feed. Can be scoped by passing options, which also allows for paginating the contents of the feed using the before and after cursors.

Params

optionsFeedClientOptions*Feed options to apply to the fetch. Will override any options specified in the FeedManager constructor.

Returns

Result<Feed, Error>

Example


makeBulkStatusUpdate

Updates all of the items within the feed with the given status. Can be passed options to scope the request further. Note: this method returns a BulkUpdate via the Knock API, which is an async operation.

Params

typeBulkChannelMessageStatusUpdateType*The type of update to make in bulk.
optionsFeedClientOptions*Feed options to scope the bulk update by.

Returns

Result<BulkOperation, Error>


FeedManager.FeedClientOptions

Used to scope a feed request.

Params

beforestringA cursor to return records before, used for pagination
afterstringA cursor to return records after, used for pagination
page_sizenumberThe maximum number of items to return per page
statusFeedItemScopeOne of either `all`, `unread`, `read`, `unseen`, `seen`
sourcestringScope to a single workflow source for the feed items
tenantstringScope to a single tenant
has_tenantbooleanScope to whether the feed items have or do not have a tenant set
archivedFeedItemArchivedScopeScope by archive status. One of `include`, `exclude`, or `only`
trigger_datamapMatch a set of trigger data on the generated feed messages