On this page

Links

Swift Chat SDK lets you encode URLs that begin with www, http, or https (plain links) so that they can be rendered as links.

Generic referencing

Channel references, user mentions, and links are instances of MessageElement with different MentionTarget types.

addMention() lets you replace a plain link on the draft message to display a meaningful text in the published message.

Method signature

You can attach links to a draft message by calling the addMention() method with the target of MentionTarget.url.

Refer to the addMention() method for details.

Sample code

Sample code

The code samples in Swift Chat SDK focus on asynchronous code execution.

You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.

Create the Hello Alex! I have sent you this link on the #offtopic channel. message where link is a URL.

1

removeMention() lets you remove a previously added link from a draft message.

Method signature

You can remove links from a draft message by calling the removeMention() method at the exact offset where the link starts.

Refer to the removeMention() method for details.

Offset value

If you don't provide the position of the first character of the message element to remove, it isn't removed.

Sample code

Sample code

The code samples in Swift Chat SDK focus on asynchronous code execution.

You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.

Remove the link from the Hello Alex! I have sent you this link on the #offtopic channel. message where link is a URL.

1

The message elements listener returns all links referenced in the draft message that match the provided 3-letter string from your app's keyset.

icon

Single listener

Method signature

You must add a message elements listener to receive link suggestions.

Refer to the addChangeListener() method for details.

Sample code

Sample code

The code samples in Swift Chat SDK focus on asynchronous code execution.

You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.

1

To return all text links in a given message, use the getMessageElements() method.

Method signature

This method has the following signature:

1message.getMessageElements()

Sample code

Sample code

The code samples in Swift Chat SDK focus on asynchronous code execution.

You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.

Get all text links included in the message with the 16200000000000000 timetoken.

1

You can access the textLinks property of the Message object to return all text links in a given message.

Method signature

This is how you can access the property:

1message.textLinks

Sample code

Sample code

The code samples in Swift Chat SDK focus on asynchronous code execution.

You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.

Get all text links included in the message with the 16200000000000000 timetoken.

1

Last updated on